Parse JSON string in JavaScript
Question:
How to parse JSON string in JavaScript? Answer:
let jsonStr = '{"id":1, "username":"john", "creationDate":"2020-11-24"}';
let user = JSON.parse(jsonStr);
Description:
Nowadays, JSON is one of the most widely used file format because - despite its name - it is language-independent and can be read by both humans and machines. In JavaScript the JSON
object contains methods for parsing JSON strings and converting values to JSON format.
The JSON.parse()
method parses a JSON string, constructing the JavaScript value or object described by the string.
Reference:
JSON parse reference
Share "How to parse JSON string in JavaScript?"
Related snippets:
Tags:
parse json string, json to object, json decode Technical term:
Parse JSON string in JavaScript