JSON and data conversion
JSON and data conversion
JSON is a text format for structured data. JSON.stringify converts supported JavaScript values to JSON text; JSON.parse converts valid JSON text into JavaScript values. Handle parse errors when input may be malformed.
Try it yourself
Change the example, run it, and explain the result in your own words. Then create one variation of your own.
Key idea
Use the example as a starting point, not something to memorize. Practise, inspect the result and make small improvements.
Code example
const text = JSON.stringify({ course: "CSS", lessons: 12 });
const data = JSON.parse(text);
console.log(data.course);