Converting a JSON string to JavaScript Object is extremely useful. In this quick guide, you will learn to use JSON.parse with examples.
Case:
Once you get the data from the server through an API, it's in string format. To utilize that data in your application, you must do the parsing.
The easiest way to parse JSON is with the JSON.parse() method. It converts a string into an instance of an object.
🔥 JSON.parse() converts JSON string into JavaScript Object.
😎 You will mostly use it after fetching the data from the server by using an API call.
😮 If you want to convert JavaScript object to JSON string, you can use JSON.stringify().
Output:
That's it! 😀
You can learn more on MDN about JSON.parse.
Don't forget to share with others.