HTML CSS Bootstrap JavaScript jQuery MySQL PHP Data Mining

JSON Syntax Rules

JSON syntax is a subset of the JavaScript object notation syntax. It is much stricter than standard JavaScript objects, and failure to follow even one small rule (like a missing comma or a single quote) will result in a parsing error.


Interactive Syntax Validator

Try writing some JSON below. Click "Validate" to check if it follows the strict rules:


1. Name/Value Pairs

JSON data is written as name/value pairs. A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value.

"firstName": "John"
Strict Rule: In JSON, field names (keys) MUST be double-quoted. Standard JS objects don't always require this, but JSON does.

2. Separation by Commas

Every name/value pair in an object must be separated by a comma (,). However, **do not** place a comma after the last pair.

{
  "city": "New York",
  "zip": 10001
}

3. Objects vs. Arrays

JSON Objects {}

Objects are surrounded by curly braces. They contain unordered key-value pairs.

JSON Arrays []

Arrays are surrounded by square brackets. They contain an ordered list of values.


Valid Data Types

A JSON value can be:

  • A string (must use double quotes)
  • A number (no quotes)
  • An object
  • An array
  • A boolean (true/false)
  • null

Invalid Data Types

You cannot use the following in standard JSON:

  • Functions
  • Dates (Must be stored as strings)
  • Undefined

JSON Files & MIME Type

  • The file extension for JSON files is .json
  • The MIME type for JSON text is application/json

Key Points to Remember

  • Curly braces hold objects.
  • Square brackets hold arrays.
  • Double quotes are required for names and strings.
  • Colons : separate names from values.
  • Commas , separate items.
  • JSON is case-sensitive.