Search notes:

JSON - JavaScript Object Notation

JSON is a simple (as in lightweight) standard for exchanging (structured) data.
The media type for JSON is application/json.

Features and design goals

The main features and design goals of JSON include
Because of this simplicity, JSON has become popular and many websites use JSON instead of XML to serialize data for communication between server applications and their clients.

Javascript origin

JSON originates from the object literals of JavaScript (ECMAScript) and is specified in RFC 8259 (The JavaScript Object Notation (JSON) Data Interchange Format) which obsoleted RFC 7159.
In fact, JSON is referred in ECMA-262 (see also ECMA-404 (The JSON Data Interchange Format)).
Because the JSON syntax originates in JavaScript, it is possible to use eval(jsonDocument) in JavaScript to parse a JSON document.
Of course, this poses a security risk (like that of SQL injection) if the JSON document contains executable code.

Tokens

The grammar of JSON has only six structural characters:
{ and } They contain an object
[ and ] They contain the elements of an array
: The colon separates a key from a value in an object
, The comman separates the elements in an array
Besides them, there are three other kinds of tokens:

Comments

The JSON specification does not support comments in JSON.

Primitive data types (scalars)

JSON specifies four primitive data types. Each scalar value has one of these data types.
Data Type Example Comment
String "string" A sequence of zore or more Unicode characters (UTF-8 (default), UTF-16 or UTF-32).
Number 42, -13.9 Represented in base 10; leading zeros or plus signs are not allowed.
Boolean true, false The only two values whose data type is boolean.
Null null The only value whose data type is null.

Strings

RFC-7159 contains the following remarks about strings (especially about using the backslash character which is called the reverse solidus in the document):
The representation of strings is similar to conventions used in the C family of programming languages. A string begins and ends with quotation marks. All Unicode characters may be placed within the quotation marks, except for the characters that must be escaped: quotation mark, reverse solidus [aka backslash], and the control characters (U+0000 through U+001F).
Any character may be escaped. If the character is in the Basic Multilingual Plane […], then it may be represented as a six-character sequence: a reverse solidus, followed by the lowercase letter u, followed by four hexadecimal digits that encode the character's code point.
RFC-7159 also says that some characters can be represented with two characters: \n, \t, \\ etc.
Thus, the following is a correct JSON string that contains quotes and a new line: "He said:\n\"hello\".".

No built-in date type

JSON does not specify a data-type for dates and/or times.
Dates are generally stored in JSON as strings in the ISO 8601 format.
This StackOverflow answer recommends to use the format that is returned by JavaScript's method Date.ToJSON(), for example 2012-04-23T18:25:43.511Z.

Structured types

The primitive data types are building blocks to create structured types.
There are two structured types:
objects Unordered set name/value pairs
arrays Ordered list of values (whose data type need not to be the same)
The terms object and array have their origins in JavaScript (see JavaScript objects and arrays)

Objects

JSON objects are embedded in curly braces ({ … }).
A JSON object consists of comma separated key-value pairs. The key is a string and is separated from the value by a colon (:).
These key value pairs are referred to as members.
{
   "item": "Lemon",
   "price": {
         "val":      1.84,
         "currency: "CHF"
   }
}

Arrays

Arrays are embedded in square brackets: [ … ].
An array is an ordered, comma-separated list of JSON values.
[ "foo",
   42,
   null,
   { "foo": "bar" }
]

Values

A value is either a primitive or a structured type.

Pretty printing JSON on the command line

The jq command line tool is arguably the best way for pretty printing JSON.
With Python, the following line would pretty print a JSON object:
echo '{"num": 42, "txt": "Hello world"}' | python -m json.tool

See also

Data exchange formats
The Python standard module json
Perl module JSON.
JSON-LD
The JavaScript object JSON.
The SQL standard included the (optional) feature for JSON support in SQL:2016.
Parsing or emitting JSON in Visual Basic for Applications (VBA):
BOMs are illegal in JSON.
The PowerShell command noun json with the two cmdlets convertTo-JSON and convertFrom-JSON.
Json.NET is a high-performance JSON framework for .NET.
Another .NET class that can be used to parse JSON is System.Web.Script.Serialization.JavaScriptSerializer.
The JSON Data Interchange Syntax is defined in ECMA-404.
The SQLcl and SQL Developer select hint /*json*/ causes an SQL result set to be returned in JSON.
JSON (as well as also for example CSV) are prone to data corruption.
A BOM is illegal in JSON (RFC 7159, Section 8.1)
GeoJSON
Oracle
jq is like sed for JSON data (curl -H "Accept: application/vnd.github.mercy-preview+json" https://api.github.com/search/repositories\?q\=topic:ecs+topic:go | jq '.items[] | {url:.url, description:.description}').

Links

JMESPath is a query language for JSON.
JSON5 is a superset of JSON that aims to alleviate some of the limitations of JSON, for example:
Papa Parse converts CSV to JSON and vice versa.
The PHP function json_decode
Reading a JSON document with d3.js (JavaScript)
JSON Web Token

Index