Working with JSON for Web Development

This chapter will help you to learn JSON fundamentals, example, syntax, array, object, encode, decode, file, date and date format. You will also be able to learn JSON examples with other technologies such as Java and PHP.

JSON - DataTypes


Valid Data Types

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

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

JSON values cannot be one of the following data types:

  • a function
  • a date
  • undefined

JSON Strings

Strings in JSON must be written in double quotes.

See this example:

{ "name":"John" }

JSON Numbers

Numbers in JSON must be an integer or a floating point.

See this example:

{ "age":30 }

JSON Objects

Values in JSON can be objects.

See this example:

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

JSON Arrays

Values in JSON can be arrays.

See this example:

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

JSON Booleans

Values in JSON can be true/false.

See this example:

{ "sale":true }

JSON null

Values in JSON can be null.

See this example:

{ "middlename":null }