How to remove " from my Json in javascript?

Javascript

Javascript Problem Overview


I am trying to inject json into my backbone.js app. My json has " for every quote.

Is there a way for me to remove this?
I've provided a sample below:

[{"Id":1,"Name":"Name}]

Javascript Solutions


Solution 1 - Javascript

Presumably you have it in a variable and are using JSON.parse(data);. In which case, use:

JSON.parse(data.replace(/"/g,'"'));

You might want to fix your JSON-writing script though, because " is not valid in a JSON object.

Solution 2 - Javascript

Accepted answer is right, however I had a trouble with that. When I add in my code, checking on debugger, I saw that it changes from

result.replace(/"/g,'"')

to

result.replace(/"/g,'"')

Instead of this I use that:

result.replace(/(&quot\;)/g,"\"")

By this notation it works.

Solution 3 - Javascript

var data = $('<div>').html('[{&quot;Id&quot;:1,&quot;Name&quot;:&quot;Name}]')[0].textContent;

that should parse all the encoded values you need.

Solution 4 - Javascript

This is a simple way to replace " with what you need to change it - chars, strings etc.

function solve(input) {
   const replaceWith = '"' // e.g. replace &quot; by "
   const result = input.replace(/&quot;/g, replaceWith)
   return result;
} 

console.log(solve('{&quot;x&quot;:&quot;1&quot;,&quot;y&quot;:&quot;2&quot;,&quot;z&quot;:&quot;10&quot;}')
   

Solution 5 - Javascript

The following works for me:

function decodeHtml(html) {
    let areaElement = document.createElement("textarea");
    areaElement.innerHTML = html;

    return areaElement.value;
}

Solution 6 - Javascript

In my case "quot" was replaced with other characters so I found a stupid but working workaround

str.replace(/&qu/g,'').replace(/ot\;/g,'')

Solution 7 - Javascript

i used replace feature in Notepad++ and replaced &quot; (without quotes) with " and result was valid json

Solution 8 - Javascript

IF you are using SQL then you can use:

update tablename set payload = replace(payload, '&', chr(39)) where id = 'unique id';

Solution 9 - Javascript

If you are using python then you can use:

import html
l = [{&quot;Id&quot;:1,&quot;Name&quot;:&quot;Name}]
r = html.unescape(l)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFrankieView Question on Stackoverflow
Solution 1 - JavascriptNiet the Dark AbsolView Answer on Stackoverflow
Solution 2 - JavascriptefiratView Answer on Stackoverflow
Solution 3 - JavascriptJuvilView Answer on Stackoverflow
Solution 4 - JavascriptStephanie I.View Answer on Stackoverflow
Solution 5 - Javascriptlinnx88View Answer on Stackoverflow
Solution 6 - JavascriptEkradView Answer on Stackoverflow
Solution 7 - JavascriptNavinView Answer on Stackoverflow
Solution 8 - JavascriptNikitaView Answer on Stackoverflow
Solution 9 - Javascriptbigfoot88View Answer on Stackoverflow