Frankie
Frankie

Reputation: 2265

How to remove " from my Json in javascript?

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}]

Upvotes: 109

Views: 177840

Answers (9)

bigfoot88
bigfoot88

Reputation: 11

If you are using python then you can use:

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

Upvotes: -2

Stephanie I.
Stephanie I.

Reputation: 41

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

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

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

Upvotes: 3

Nikita
Nikita

Reputation: 1

IF you are using SQL then you can use:

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

Upvotes: 0

Ekrad
Ekrad

Reputation: 21

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

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

Upvotes: 1

Navin
Navin

Reputation: 161

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

Upvotes: 0

romm
romm

Reputation: 67

The following works for me:

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

    return areaElement.value;
}

Upvotes: 1

efirat
efirat

Reputation: 3867

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.

Upvotes: 24

Juvil
Juvil

Reputation: 490

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

that should parse all the encoded values you need.

Upvotes: 5

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324810

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

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

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

Upvotes: 206

Related Questions