JSON

JS JSON Syntax

JSON Syntax Rules

JavaScript JSON syntax structures data, validated with JSONLint.

Introduction to JSON Syntax

JSON (JavaScript Object Notation) is a lightweight data interchange format that's easy for humans to read and write and easy for machines to parse and generate. It is predominantly used in web applications to transmit data between a server and a client, often serving as an alternative to XML. JSON syntax is derived from JavaScript object notation syntax, but it is language-independent.

Basic JSON Syntax

JSON is built on two structures:

  • A collection of name/value pairs: In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
  • An ordered list of values: In most languages, this is realized as an array, vector, list, or sequence.

These are the building blocks for JSON data structures.

JSON Objects

A JSON object is an unordered set of key/value pairs. An object begins with a { (left brace) and ends with a } (right brace). Each key is followed by a colon : and the key/value pairs are separated by a comma ,.

JSON Arrays

A JSON array is an ordered collection of values. An array begins with a [ (left bracket) and ends with a ] (right bracket). Values are separated by a comma ,.

JSON Values

A JSON value can be one of the following types:

  • String
  • Number
  • Object (JSON object)
  • Array (JSON array)
  • Boolean (true or false)
  • null

JSON values are represented similarly to how they are in JavaScript, making it intuitive for JavaScript developers.

Validating JSON Syntax with JSONLint

JSONLint is a validator and reformatter for JSON. It aids in checking the validity of JSON files and ensuring they adhere to the correct syntax. This is particularly useful for debugging and ensuring data integrity before JSON data is sent over the network.

Simply paste your JSON data into JSONLint, and it will highlight any syntax errors and suggest corrections.