Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
97
rated 0 times [  101] [ 4]  / answers: 1 / hits: 63634  / 10 Years ago, tue, october 7, 2014, 12:00:00

I want to create a JSON string inside a JSON request. Here is my code,



Fiddle



JS



var x = {
a: 1,
b: 'a sample text',
};

var request = {
t: JSON.stringify(x),
c: 2,
r: 'some text'
};

console.log(request);


Can someone help me how to escape the double quotes?



Console



Object {
t: {a:1,b:a sample text}, //This creates a problem, double quotes inside double quotes.
c: 2,
r: some text
}


Thanks in advance.


More From » json

 Answers
30

That's just the way the browser console shows you the value of a string, by wrapping in double quotes for the output. This is perfectly normal and nothing is broken.



You can test it by transforming your JSON string back to an object and using a property.



console.log( JSON.parse(request.t).b ); // a sample text

[#69208] Sunday, October 5, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
juliettec

Total Points: 327
Total Questions: 127
Total Answers: 102

Location: Bangladesh
Member since Sat, Jan 23, 2021
3 Years ago
;