JSON Data Types


Valid Data Types

In JSON, values can only be certain types of data.

  • a string
  • a number
  • an object (JSON object)
  • an array
  • a boolean
  • null

JSON valuescannot belong to certain data types.

  • a function
  • a date
  • undefined

JSON Strings

Text in JSON needs to be enclosed within double quotes.

Example

{"name":"John"}

JSON Numbers

JSON numbers must be whole numbers or decimal numbers.

Example

{"age":30}

JSON Objects

JSON values can be objects.

Example

{
"employee":{"name":"John", "age":30, "city":"New York"}
}

Values in JSON representing objects need to adhere to the JSON syntax.


JSON Arrays

JSON values can exist as arrays.

Example

{
"employees":["John", "Anna", "Peter"]
}

JSON Booleans

In JSON, values can either be true or false.

Example

{"sale":true}

JSON null

JSON values can be empty.

Example

{"middlename":null}