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

196
Views
How to replace inner double quotes to single quote using regex

I've got something like this data that comes from API and I need to do JSON.parse this, but the problem was there were inner double quotes so I can't parse it what should I do, can I use regex or something.

const dataString = '{"EN" : "2. This English "Blha Blha"  "Woo Woo" something wrong."}';

I also used this regex

replace(/(^"|"$)|"/g, "'");

but by using this regex it's replace all the double quotes with single quotes like this =>

{'EN' : '2. This English 'Blha Blha'  'Woo Woo' something wrong.'};

I only want to replace the quotes like this

{'EN' : '2. This English "Blha Blha"  "Woo Woo" something wrong.'};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The thing is that single quotes are not valid symbols for JSON if they are used to wrap key/values. To make it clear - you need to escape double-quote symbols in values. A better approach is to update your API with that correction. More ugly but working way is placed below:

const dataString = '{"EN" : "2. This English "Blha Blha"  "Woo Woo" something wrong."}';
const normalize = (dataString) => {
  let newString = dataString;
  newString = newString.replaceAll(`"`, `\\\"`);
  newString = newString.replaceAll(`{\\\"`, `{"`);
  newString = newString.replaceAll(`\\\"}`, `"}`);
  newString = newString.replaceAll(`\\\" : \\\"`, `" : "`);
  return newString;
};
console.log(JSON.parse(normalize(dataString)));

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!