converting JSON object to string
How can we convert a JSON Object to string?
for example, if you have a JSON object as given below
1 2 3 4 |
var user = { "name": "Jacob Nelson", "role": "Story\n Manager" } |
using toString will not help.
1 |
user.toString() |
will result in
1 |
"[object Object]" |
The right way is to use JSON.stringify()
1 |
JSON.stringify(user) |
will result in
1 |
"{\"name\":\"Jacob Nelson\",\"role\":\"Story\\n Manager\"}" |
Leave a Reply