RFC 7159: The JavaScript Object Notation (JSON) Data Interchange Format

Obsoleted by: 8259 PROPOSED STANDARD

Errata Exist

Internet Engineering Task Force (IETF)                      T. Bray, Ed.
Request for Comments: 7159                                  Google, Inc.
Obsoletes: 4627, 7158                                         March 2014
Category: Standards Track
ISSN: 2070-1721


     

The JavaScript Object Notation (JSON) Data Interchange Format

Abstract JavaScript Object Notation (JSON) is a lightweight, text-based, language-independent data interchange format. It was derived from the ECMAScript Programming Language Standard. JSON defines a small set of formatting rules for the portable representation of structured data. This document removes inconsistencies with other specifications of JSON, repairs specification errors, and offers experience-based interoperability guidance. Status of This Memo This is an Internet Standards Track document. This document is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community. It has received public review and has been approved for publication by the Internet Engineering Steering Group (IESG). Further information on Internet Standards is available in Section 2 of RFC 5741. Information about the current status of this document, any errata, and how to provide feedback on it may be obtained at http://www.rfc-editor.org/info/rfc7159.

Bray Standards Track [Page 1]

RFC 7159 JSON March 2014BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. This document may contain material from IETF Documents or IETF Contributions published or made publicly available before November 10, 2008. The person(s) controlling the copyright in some of this material may not have granted the IETF Trust the right to allow modifications of such material outside the IETF Standards Process. Without obtaining an adequate license from the person(s) controlling the copyright in such materials, this document may not be modified outside the IETF Standards Process, and derivative works of it may not be created outside the IETF Standards Process, except to format it for publication as an RFC or to translate it into languages other than English.

Bray Standards Track [Page 2]

RFC 7159 JSON March 20141.1 . Conventions Used in This DocumentRFC2119]. The grammatical rules in this document are to be interpreted as described in [RFC5234]. 1.2 . Specifications of JSONRFC4627], which describes JSON and registers the media type "application/json". A description of JSON in ECMAScript terms appears in Version 5.1 of the ECMAScript specification [ECMA-262], Section 15.12. JSON is also described in [ECMA-404]. All of the specifications of JSON syntax agree on the syntactic elements of the language. 1.3 . Introduction to This RevisionRFC 4627, JSON has found very wide use. This experience has revealed certain patterns, which, while allowed by its specifications, have caused interoperability problems. Also, a small number of errata have been reported (see RFC Errata IDs 607 [Err607] and 3607 [Err3607]). This document's goal is to apply the errata, remove inconsistencies with other specifications of JSON, and highlight practices that can lead to interoperability problems. 2 . JSON Grammar

Bray Standards Track [Page 4]

RFC 7159 JSON March 20143 . Values

Bray Standards Track [Page 5]

RFC 7159 JSON March 2014IEEE754] is generally available and widely used, good interoperability can be achieved by implementations that expect no more precision or range than these provide, in the sense that implementations will approximate JSON numbers within the expected precision. A JSON number such as 1E400 or 3.141592653589793238462643383279 may indicate potential interoperability problems, since it suggests that the software that created it expects receiving software to have greater capabilities for numeric magnitude and precision than is widely available. Note that when such software is used, numbers that are integers and are in the range [-(2**53)+1, (2**53)-1] are interoperable in the sense that implementations will agree exactly on their numeric values.

Bray Standards Track [Page 7]

RFC 7159 JSON March 20147 . Strings

Bray Standards Track [Page 8]

RFC 7159 JSON March 20148 . String and Character Issues8.1 . Character Encoding8.2 . Unicode CharactersUNICODE] (however escaped), then that JSON text is interoperable in the sense that all software implementations that parse it will agree on the contents of names and of string values in objects and arrays. However, the ABNF in this specification allows member names and string values to contain bit sequences that cannot encode Unicode characters; for example, "\uDEAD" (a single unpaired UTF-16 surrogate). Instances of this have been observed, for example, when a library truncates a UTF-16 string without checking whether the truncation split a surrogate pair. The behavior of software that receives JSON texts containing such values is unpredictable; for example, implementations might return different values for the length of a string value or even suffer fatal runtime exceptions. 8.3 . String Comparison

Bray Standards Track [Page 9]

RFC 7159 JSON March 20149 . Parsers10 . Generators11 . IANA Considerations[RFC7159], Section 12. Interoperability considerations: Described in [RFC7159] Published specification: [RFC7159] Applications that use this media type: JSON has been used to exchange data between applications written in all of these programming languages: ActionScript, C, C#, Clojure, ColdFusion, Common Lisp, E, Erlang, Go, Java, JavaScript, Lua, Objective CAML, Perl, PHP, Python, Rebol, Ruby, Scala, and Scheme.

Bray Standards Track [Page 10]

RFC 7159 JSON March 201412 . Security Considerations

Bray Standards Track [Page 11]

RFC 7159 JSON March 201413 . Examples

Bray Standards Track [Page 12]

RFC 7159 JSON March 2014Appendix A . Changes from RFC 4627 RFC 4627. o Changed the title and abstract of the document. o Changed the reference to [UNICODE] to be not version specific. o Added a "Specifications of JSON" section. o Added an "Introduction to This Revision" section. o Changed the definition of "JSON text" so that it can be any JSON value, removing the constraint that it be an object or array. o Added language about duplicate object member names, member ordering, and interoperability. o Clarified the absence of a requirement that values in an array be of the same JSON type. o Applied erratum #607 from RFC 4627 to correctly align the artwork for the definition of "object". o Changed "as sequences of digits" to "in the grammar below" in the "Numbers" section, and made base-10-ness explicit. o Added language about number interoperability as a function of IEEE754, and added an IEEE754 reference. o Added language about interoperability and Unicode characters and about string comparisons. To do this, turned the old "Encoding" section into a "String and Character Issues" section, with three subsections: "Character Encoding", "Unicode Characters", and "String Comparison". o Changed guidance in the "Parsers" section to point out that implementations may set limits on the range "and precision" of numbers. o Updated and tidied the "IANA Considerations" section. o Made a real "Security Considerations" section and lifted the text out of the previous "IANA Considerations" section.

Bray Standards Track [Page 15]

RFC 7159 JSON March 2014RFC 4627 by removing the security consideration that begins "A JSON text can be safely passed" and the JavaScript code that went with that consideration. o Added a note to the "Security Considerations" section pointing out the risks of using the "eval()" function in JavaScript or any other language in which JSON texts conform to that language's syntax. o Added a note to the "IANA Considerations" clarifying the absence of a "charset" parameter for the application/json media type. o Changed "100" to 100 and added a boolean field, both in the first example. o Added examples of JSON texts with simple values, neither objects nor arrays. o Added a "Contributors" section crediting Douglas Crockford. o Added a reference to RFC 4627. o Moved the ECMAScript reference from Normative to Informative and updated it to reference ECMAScript 5.1, and added a reference to ECMA 404. Author's Address Tim Bray (editor) Google, Inc. EMail: [email protected] Bray Standards Track [Page 16]