Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

87
Views
How to parse string with break lines to object

Is there a possible way to parse a string with breaklines to an object using JSON.parse?

const text = '{ "name": "Anne", "desc": "Hi,\nThis is me" }';
const obj = JSON.parse(text);
console.log(obj);

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There are two things here:

  1. To answer your question, you simply need to escape the character like this:
"Hi,\\nThis is me"
  1. For your code specifically, you also have another syntax error with a ,, instead of a ::
    const text = '{ "name": "Anne", "desc": "Hi,\\nThis is me" }';
    const obj = JSON.parse(text);
    console.log(obj);

output:

{
name: "Anne" ,
desc: "Hi, This is me"
} 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!