In Node.js, how do I turn a string to a json?

JavascriptJsonHttpnode.js

Javascript Problem Overview


For example, a HTTP REST API just returned me a JSON, but of course it's a string right now. How can I turn it into a JSON?

Javascript Solutions


Solution 1 - Javascript

You need to use this function.

JSON.parse(yourJsonString);

And it will return the object / array that was contained within the string.

Solution 2 - Javascript

use the JSON function >

JSON.parse(theString)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTIMEXView Question on Stackoverflow
Solution 1 - JavascriptOlicalView Answer on Stackoverflow
Solution 2 - JavascriptneebzView Answer on Stackoverflow