JSON Data Types

JSON Data Types

JSON strictly limits the types of data that can be included inside its string structure.

This strictness ensures that JSON data can be decoded by any programming language safely!


Valid JSON Data Types

In JSON, values must be one of the following exact data types:


Invalid Data Types

JSON values cannot be JavaScript-specific elements like a function, a date, or undefined.

If you attempt to stringify a function, it will either throw an error or be completely removed from the data.

To pass a date, you must first convert the date object into a standard string!

Data Types Example:

let jsonString = `
{
  "name": "John",           // String
  "age": 30,                // Number
  "isStudent": false,       // Boolean
  "courses": ["Math", "IT"],// Array
  "car": null               // Null
}`;

let user = JSON.parse(jsonString); console.log(user.courses[1]); // Outputs: IT


Exercise 1 of 1

?

Which of the following is NOT a valid data type in JSON?