Reputation: 2265
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
Reputation: 11
If you are using python then you can use:
import html
l = [{"Id":1,"Name":"Name}]
r = html.unescape(l)
Upvotes: -2
Reputation: 41
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 " by "
const result = input.replace(/"/g, replaceWith)
return result;
}
console.log(solve('{"x":"1","y":"2","z":"10"}')
Upvotes: 3
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
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
Reputation: 161
i used replace feature in Notepad++ and replaced "
(without quotes) with "
and result was valid json
Upvotes: 0
Reputation: 67
The following works for me:
function decodeHtml(html) {
let areaElement = document.createElement("textarea");
areaElement.innerHTML = html;
return areaElement.value;
}
Upvotes: 1
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(/("\;)/g,"\"")
By this notation it works.
Upvotes: 24
Reputation: 490
var data = $('<div>').html('[{"Id":1,"Name":"Name}]')[0].textContent;
that should parse all the encoded values you need.
Upvotes: 5
Reputation: 324810
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.
Upvotes: 206