โ† Back to Course

๐Ÿงพ JSON Fundamentals

JSON stands for JavaScript Object Notation. It is a text format used to represent structured data in a way that humans and programs can both read.

What JSON Looks Like

Example: JSON Data

{
  "name": "TypeLand",
  "topicCount": 14,
  "published": true,
  "tags": ["typescript", "coding", "json"]
}

Important JSON Rules

  • Keys use double quotes
  • Strings use double quotes
  • JSON can hold objects, arrays, numbers, booleans, strings, and null
  • JSON cannot store functions

Convert Between Objects and JSON

Example: Stringify and Parse

const user = {
  name: "Ava",
  score: 98,
};

const jsonText = JSON.stringify(user, null, 2);
console.log(jsonText);

const parsedUser = JSON.parse(jsonText);
console.log(parsedUser.name);

๐ŸŽฏ Key Ideas

  • JSON is a data format, not a programming language
  • APIs commonly send and receive JSON
  • JSON.stringify() turns an object into JSON text
  • JSON.parse() turns JSON text into data your program can use
โ† Back to Code Foundations