JSON has no version number in the file. It has been specified several times. The grammar has hardly changed, apart from what may stand at the top level. Each revision also added rules about encodings, interoperability and security, which are listed below.
The specifications
| Document | Date | What it did |
|---|---|---|
| RFC 4627 | July 2006 | The first RFC, Informational. A text had to be an object or an array. UTF-8 was the default, and UTF-16 and UTF-32 were allowed. Registered application/json. |
| ECMA-404, 1st edition | October 2013 | Ecma International’s definition of the syntax. Any value could stand at the top level. |
| RFC 7158 | March 2014 | Standards Track; obsoleted RFC 4627. Its header was misdated March 2013, and RFC 7159 reissued it the same month with the date corrected, obsoleting it. |
| RFC 7159 | March 2014 | Standards Track; obsoleted RFC 4627 and RFC 7158. A text could be any value. UTF-8, UTF-16 and UTF-32 were allowed, with UTF-8 the default. |
| RFC 8259 | December 2017 | The current RFC, also STD 90. Requires UTF-8 outside a closed ecosystem, and makes ECMA-404 a normative reference. |
| ECMA-404, 2nd edition | December 2017 | The current edition of the syntax. |
ECMA-404 and the RFCs
ECMA-404 and RFC 8259 describe the same syntax. ECMA-404 defines only the syntax. The RFC adds rules about how software should treat it: the encoding, unique names, and the limits on numbers and surrogates.
What a file needs for each
| Text | RFC 4627 | RFC 7158 and RFC 7159 | RFC 8259 |
|---|---|---|---|
| An object or array at the top | Yes | Yes | Yes |
| A string, number or literal at the top | No | Yes | Yes |
| UTF-8 | Yes | Yes | Yes |
| UTF-16 or UTF-32 between systems | Yes | Yes | No |
Because the top-level rule was widened, a program written for RFC 4627 can refuse
42 or "text", which later specifications accept.
What changed
RFC 7159, from RFC 4627
RFC 7158 and RFC 7159 have the same content. Their Appendix A lists these changes from RFC 4627:
- A new title and abstract, a reference to Unicode that names no particular version, and new sections on the specifications of JSON and on the revision itself.
- A JSON text may be any value, no longer only an object or an array, with examples of texts that are a single simple value.
- New text on repeated member names, member order and interoperability. RFC 4627 had already said names should be unique; RFC 7159 added that software receiving repeats behaves unpredictably.
- It states that the values in an array need not be of the same type.
- Erratum 607 applied: the artwork defining
objectwas realigned. - Numbers: “as sequences of digits” became “in the grammar below”, base 10 was made explicit, and text on interoperability as a function of IEEE 754 was added, with a reference to it.
- The “Encoding” section became “String and Character Issues”, with new text on Unicode characters and on comparing strings.
- Parsers may limit the range and also the precision of numbers, where RFC 4627 had mentioned range only.
- The IANA registration was tidied, with a note that
application/jsonhas nocharsetparameter. RFC 4627’s registration had given the encoding considerations as “8bit if UTF-8; binary if UTF-16 or UTF-32”; RFC 7159 and RFC 8259 give “binary”. - A real Security Considerations section, lifted out of the IANA section. Erratum 3607
applied: RFC 4627’s advice that a JSON text could safely be passed to JavaScript’s
eval()after a check with two regular expressions was removed, with its code, and a warning about the risks ofeval()and similar functions in other languages was added. - Example changes:
"100"became100and a boolean field was added to the first example. - A Contributors section crediting Douglas Crockford, a reference to RFC 4627, and the ECMAScript reference moved from normative to informative, updated to ECMAScript 5.1, with a reference to ECMA-404 added.
RFC 8259, from RFC 7159
Its Appendix A lists these changes:
- Section 1.2 now reflects the removal of a JSON specification from ECMA-262, makes ECMA-404 a normative reference, and explains what “normative” means here.
- Section 1.3 now lists errata filed against RFC 7159, not RFC 4627.
- Section 8.1 requires UTF-8 for JSON transmitted over a network.
- Section 12 describes the security risk of using ECMAScript’s
eval()on JSON more precisely. - ECMA-404 moved from the informative references to the normative ones; the ECMA-262 version and the errata list in the informative references were updated.