Skip to content Skip to sidebar Skip to footer

How To Convert JSON String Sent From A Server Into A JavaScript Object

I would like to be able to convert the JSON string sent from the server into a JavaScript object on a HMTL page. The raw JSON string data is being displayed, but I would rather dis

Solution 1:

If you're planning on using the JSON for anything, as in traversing and reading the data from that, then JSON.parse() is exactly what you need. Pretty-printing is something only useful for humans, so unless you're exclusively using the output for human consumption, the result you have should be fine.

However, if you are going to just show the data, then I would recommend just formatting the output into some HTML/CSS display.

But assuming you are planning on using the data for something, as mentioned before and by others, JSON.parse() is all you need to generate a JS object.


Post a Comment for "How To Convert JSON String Sent From A Server Into A JavaScript Object"