Understanding JSON — The Language of Data Exchange
Learn what JSON is, how to read and write it, and why it is the most popular format for sending data between apps.
What is JSON?
JSON Syntax
{
"name": "Maya",
"age": 12,
"isStudent": true,
"hobbies": ["coding", "drawing", "gaming"],
"school": {
"name": "Oakwood Middle",
"grade": 7
},
"pet": null
}JSON Rules and Data Types
Working with JSON in JavaScript
// Convert a JavaScript object to a JSON string
let student = { name: 'Maya', age: 12, grade: 7 };
let jsonString = JSON.stringify(student);
console.log(jsonString);
// Output: {"name":"Maya","age":12,"grade":7}
// Convert a JSON string back to an object
let data = JSON.parse(jsonString);
console.log(data.name); // Maya
console.log(data.age); // 12When debugging JSON, use a JSON formatter tool (search 'JSON formatter' online). These tools take messy, unformatted JSON and display it with nice indentation and color-coding. Most browsers also format JSON automatically if you visit a URL that returns JSON data.
Create a JSON file that describes your favorite video game. Include: the name (string), year released (number), your rating out of 10 (number), whether you have finished it (boolean), a list of genres (array of strings), and the developer as a nested object with name and country. Make sure your JSON is valid — try pasting it into jsonlint.com to check for errors!
Ready to build?
Put what you learned into practice — pick a project and start coding.
Start Building Free