Skip to content
UNASPACE

JSON stands for JavaScript Object Notation. It is a simple text format used to store and send data.

You will often see JSON in APIs, config files, and when applications send data between frontend and backend.

  • Easy for humans to read
  • Easy for programs to parse
  • Works in many programming languages
  • Common format for API requests and responses

JSON uses:

  • Curly braces {} for objects
  • Square brackets [] for arrays
  • Double quotes "" for keys and string values

Example:

{
"name": "Sara",
"age": 20,
"isStudent": true
}

JSON supports these value types:

  • String
  • Number
  • Boolean
  • Object
  • Array
  • null

Example:

{
"name": "Sara",
"age": 20,
"skills": ["HTML", "CSS", "JavaScript"],
"address": {
"city": "Paramaribo"
},
"graduated": false,
"nickname": null
}
  • Keys must use double quotes
  • Strings must use double quotes
  • Items are separated by commas
  • JSON cannot contain functions
  • JSON does not allow undefined

They look similar, but they are not the same.

  • JSON is plain text
  • A JavaScript object is a value inside JavaScript code
  • JSON must use double quotes

JavaScript object:

const user = { name: 'Sara', age: 20 };

JSON text:

{
"name": "Sara",
"age": 20
}

Use JSON.stringify() to turn a JavaScript object into JSON text.

const user = { name: 'Sara', age: 20 };
const text = JSON.stringify(user);

Use JSON.parse() to turn JSON text into a JavaScript object.

const text = '{"name":"Sara","age":20}';
const user = JSON.parse(text);
  • Using single quotes instead of double quotes
  • Forgetting a comma
  • Adding a trailing comma at the end
  • Using undefined in JSON

Wrong:

{
"name": "Sara"
}

Correct:

{
"name": "Sara"
}
Built with passion by Ngineer Lab