JSON#Native encoding and decoding in browsers>native JSON

aesthetics  →
being  →
complexity  →
database  →
enterprise  →
ethics  →
fiction  →
history  →
internet  →
knowledge  →
language  →
licensing  →
linux  →
logic  →
method  →
news  →
perception  →
philosophy  →
policy  →
purpose  →
religion  →
science  →
sociology  →
software  →
truth  →
unix  →
wiki  →
essay  →
feed  →
help  →
system  →
wiki  →
critical  →
discussion  →
forked  →
imported  →
original  →
JSON#Native encoding and decoding in browsers>native JSON
[ temporary import ]
please note:
- the content below is remote from Wikipedia
- it has been imported raw for GetWiki
{{short description|Text-based open standard designed for human-readable data interchange}}{{Redirect|Json|people with similar names|J Son (disambiguation){{!}}J Son}}

, ECMA-404, ISO/IEC 21778:2017| free = Yesweblink}}}}In computing, JavaScript Object Notation (JSON) ({{IPAc-en|ˈ|dʒ|eɪ|s|ən}} "Jason",WEB, Doug Crockford "Google Tech Talks: JavaScript: The Good Parts", 7 February 2009,weblink WEB, Douglas Crockford: pronouncing, Nov 14, 2014,weblink {{IPAc-en|ˈ|dʒ|eɪ|s|ɒ|n}}) is an open-standard file format that uses human-readable text to transmit data objects consisting of attribute–value pairs and array data types (or any other serializable value). It is a very common data format used for asynchronous browser–server communication, including as a replacement for XML in some AJAX-style systems.WEB, A Modern Reintroduction To AJAX,weblink 12 April 2017, jajax, JSON is a language-independent data format. It was derived from JavaScript, but many modern programming languages include code to generate and parse JSON-format data. The official Internet media type for JSON is application/json. JSON filenames use the extension .json.Douglas Crockford originally specified the JSON format in the early 2000s. It was first standardized in 2013 in {{IETF RFC|7158}} and ECMA-404.WEB,weblink Standard ECMA-404,, The latest JSON format standard was published in 2017 as {{IETF RFC|8259}}, and remains consistent with ECMA-404. That same year, JSON was also standardized as ISO/IEC 21778:2017.WEB,weblink ISO/IEC 21778:2017, 14:00-17:00, ISO, en, 2019-07-29, The ECMA and ISO standards describes only the allowed syntax, whereas the RFC covers some security and interoperability considerations.BRAY>FIRST= TIM, JSON Redux AKA RFC8259,weblinkaccessdate= 16 March 2014,


{{Refimprove section|date=March 2018}}(File:Douglas Crockford.jpg|thumb|Douglas Crockford at the Yahoo Building. (2007))JSON grew out of a need for stateless, real-time server-to-browser communication protocol without using browser plugins such as Flash or Java applets, the dominant methods used in the early 2000s.{{Citation needed|date=December 2016}}Douglas Crockford first specifiedWEB,weblink Douglas Crockford — The JSON Saga, YouTube, 28 August 2011, 23 September 2016, and popularized the JSON format. The acronym originated at State Software, a company co-founded by Crockford and others in March 2001. The co-founders agreed to build a system that used standard browser capabilities and provided an abstraction layer for Web developers to create stateful Web applications that had a persistent duplex connection to a Web server by holding two HTTP connections open and recycling them before standard browser time-outs if no further data were exchanged. The co-founders had a round-table discussion and voted whether to call the data format JSML or JSON, as well as under what license type to make it available. {{Anchor|License}}Crockford, being inspired by the words of then President Bush, should also be credited with coming up with the "evil-doers" JSON license ("The Software shall be used for Good, not Evil.") in order to open-source the JSON libraries, but force (troll) corporate lawyers, or those who are overly pedantic, to seek to pay for a license from State. Chip Morningstar developed the idea for the State Application Framework at State Software.WEB, Chip Morningstar Biography, n.d.,weblink NEWS,weblink State Software Breaks Through Web App Development Barrier With State Application Framework: Software Lets Developers Create Truly Interactive Applications; Reduces Costs, Development Time and Improves User Experience, February 12, 2002, PR Newswire, March 19, 2013,weblink" title="">weblink June 5, 2013, yes, mdy-all,
On the other hand, this clause led to license compatibility problems of the JSON license with other open-source licenses.Apache and the JSON license on by Jake Edge (November 30, 2016)
A precursor to the JSON libraries was used in a children's digital asset trading game project named Cartoon Orbit at (the State co-founders had all worked at this company previously) for Cartoon Network, which used a browser side plug-in with a proprietary messaging format to manipulate DHTML elements (this system is also owned by 3DO). Upon discovery of early Ajax capabilities, digiGroups, Noosh, and others used frames to pass information into the user browsers' visual field without refreshing a Web application's visual context, realizing real-time rich Web applications using only the standard HTTP, HTML and JavaScript capabilities of Netscape 4.0.5+ and IE 5+. Crockford then found that JavaScript could be used as an object-based messaging format for such a system. The system was sold to Sun Microsystems, and EDS. The JSON.orgWEB,weblink JSON,, website was launched in 2002. In December 2005, Yahoo! began offering some of its Web services in JSON.WEB,weblink Using JSON with Yahoo! Web services, Yahoo!, July 3, 2009,weblink" title="">weblink October 11, 2007, Yahoo!, JSON was originally intended to be a subset of the JavaScript scripting language (specifically, Standard ECMA-262 3rd Edition—December 1999HTTP://JSON.ORG > TITLE = INTRODUCING JSON FIRST=DOUGLAS AUTHORLINK=DOUGLAS CROCKFORD ACCESSDATE=JULY 3, 2009, {{Request quotationLanguage-independent specification>language-independent data format. Code for parsing and generating JSON data is readily available in many programming languages. JSON's website lists JSON libraries by language.Though JSON was originally advertised and believed to be a strict subset of JavaScript and ECMAScript,WEB,weblink JSON in JavaScript, 2016-07-10, 2016-08-13, Douglas Crockford, bot: unknown,weblink" title="">weblink 2016-07-10, {{failed verification|date=January 2017}} it inadvertently allows some unescaped characters in strings that are illegal in JavaScript and ECMAScript string literals. See Data portability issues below.JSON itself became an ECMA international standard in 2013 as the ECMA-404 standard.WEB,weblink publisher= ECMA International accessdate= 23 September 2016, In the same year {{IETF RFC|7158}} used ECMA-404 as reference. In 2014 {{IETF RFC|7159}} became the main reference for JSON's internet uses (ex. MIME application/json), and obsoletes {{IETF RFC|4627}} and {{IETF RFC|7158}} (but preserving ECMA-262 and ECMA-404 as main references). ISO/IEC JTC 1/SC 22 published ISO/IEC 21778:2017 as an international standard in November 2017. In December 2017, {{IETF RFC|7159}} was made obsolete by {{IETF RFC|8259}}.

Data types and syntax

JSON's basic data types are:
  • Number: a signed decimal number that may contain a fractional part and may use exponential E notation, but cannot include non-numbers such as NaN. The format makes no distinction between integer and floating-point. JavaScript uses a double-precision floating-point format for all its numeric values, but other languages implementing JSON may encode numbers differently.
  • String: a sequence of zero or more Unicode characters. Strings are delimited with double-quotation marks and support a backslash escaping syntax.
  • Boolean: either of the values true or false
  • Array: an ordered list of zero or more values, each of which may be of any type. Arrays use square bracket notation with comma-separated elements.
  • Object: an unordered collection of name–value pairs where the names (also called keys) are strings. Since objects are intended to represent associative arrays, it is recommended, though not required, that each key is unique within an object. Objects are delimited with curly brackets and use commas to separate each pair, while within each pair the colon ':' character separates the key or name from its value.
  • null: An empty value, using the word null
Whitespace is allowed and ignored around or between syntactic elements (values and punctuation, but not within a string value). Four specific characters are considered whitespace for this purpose: space, horizontal tab, line feed, and carriage return. In particular, the byte order mark must not be generated by a conforming implementation (though it may be accepted when parsing JSON). JSON does not provide syntax for comments.Early versions of JSON (such as specified by {{IETF RFC|4627}}) required that a valid JSON text must consist of only an object or an array type, which could contain other types within them.


The following example shows a possible JSON representation describing a person.{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 27,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
"phoneNumbers": [
"type": "home",
"number": "212 555-1234"
"type": "office",
"number": "646 555-4567"
"type": "mobile",
"number": "123 456-7890"
"children": [],
"spouse": null

Data portability issues

{{Contains emoticon|section|image=}}Although Douglas Crockford originally asserted that JSON is a strict subset of JavaScript, his specification actually allows valid JSON documents that are invalid JavaScript. Specifically, JSON allows the Unicode line terminators {{unichar|2028|LINE SEPARATOR}} and {{unichar|2029|PARAGRAPH SEPARATOR}} to appear unescaped in quoted strings, while ECMAScript 2018 and older does not.WEB,weblink JSON: The JavaScript subset that isn't, Holm, Magnus, 15 May 2011, The timeless repository, 23 September 2016, WEB,weblink TC39 Proposal: Subsume JSON, 22 May 2018, ECMA TC39 committee, This is a consequence of JSON disallowing only "control characters". For maximum portability, these characters should be backslash-escaped. This subtlety is important when generating JSONP.JSON exchange in an open ecosystem must be encoded in UTF-8.WEB,weblink The JavaScript Object Notation (JSON) Data Interchange Format, IETF, December 2017, 16 February 2018, The encoding supports the full Unicode character set, including those characters outside the Basic Multilingual Plane (U+10000 to U+10FFFF). However, if escaped, those characters must be written using UTF-16 surrogate pairs, a detail missed by some JSON parsers. For example, to include the Emoji character {{unichar|1F602|FACE WITH TEARS OF JOY}} in JSON:{ "face": "😂" }// or{ "face": "uD83DuDE02" }Numbers in JSON are agnostic with regard to their representation within programming languages. While this allows for numbers of arbitrary precision to be serialized, it may lead to portability issues. For example, since no differentiation is made between integer and floating-point values, some implementations may treat 42, 42.0, and 4.2E+1 as the same number, while others may not. The JSON standard make no requirements regarding implementation details such as overflow, underflow, loss of precision, rounding, or signed zeros, but it does recommend to expect no more than IEEE 754 binary64 precision for "good interoperability". There is no inherent precision loss in serializing a machine-level binary representation of a floating-point number (like binary64) into a human-readable decimal representation (like numbers in JSON), and back, since there exist published algorithms to do this exactly and optimally.WEB,weblink Printing Floating-Point Numbers - An Always Correct Method, Andrysco, Marc, Jhala, Ranjit, Lerner, Sorin, 2019-07-27,

Using JSON in JavaScript

{{As of|2018}}, all major browsers support at least the fifth edition ECMAScript which providesWEB,weblink Standard ECMA-262,, 13 September 2015, a safe and fast method of decoding JSON:var p = JSON.parse(json_string);

Unsupported native data types

JavaScript syntax defines several native data types that are not included in the JSON standard:WEB,weblink JSON Web Token (JWT), IETF, May 2015, 23 September 2016, Map, Set, Date, Error, Regular Expression, Function, Promise, and undefined.The undefined type was left out of the JSON standard, and one finds suggestions that null be used instead.In fact, the current standard says that for a sparse array such as:
var v = [0];
v[3] = 3;
which behaves in JavaScript as if it were:
var vx = [0, undefined, undefined, 3];
with the undefined entries being only implicit rather than explicit, should translate to JSON as if it were:
var vx = [0, null, null, 3];
with explicit null fillers for the undefined entries.Furthermore, in JavaScript {a: undefined} often behaves the same as {}. Both translate as "{}" in JSON. However undefined as an explicit property value does have use in JavaScript inheritance situations such as:
var x = {a: 1};
var xi = Object.create(x);
xi.a = undefined;
where the inheritance of x's property a is overridden in xi and makes it pretty much behave as if nothing was inherited. JSON.stringify itself ignores inherited values - it only translates the enumerable own properties as given by Object.keys(y). The default stringification, while not encoding inheritance, can (except for undefined values) encode enough of an object to reconstruct it in an environment that knows what inheritance it should have.To encode JavaScript objects that contain explicit undefined values a convention for representing undefined must be established, such as mapping it to the string "UNDEFINED". One can then pass JSON.stringify the optional replacer argument to translate with this convention:
var y = {a: undefined};
var ys = JSON.stringify(y,
function (k, v){return (v === undefined) ? "UNDEFINED" : v});
Converting this JSON back into JavaScript is not as straightforward. While JSON.parse can take an optional reviver argument that is, essentially, the inverse of a replacer, it can't be used in this situation. If that function returns undefined, the JSON.parse logic interprets this to mean to not define a property rather than define one with a undefined value. Instead one has to explicitly post process the result from JSON.parse replacing each "UNDEFINED" with undefined.
These JavaScript data types must be represented by some other data format, with the programs on both ends agreeing on how to convert between the types. {{As of|2011}}, there are some de facto standards, e.g., converting from Date to String, but none universally recognized.WEB,weblink jquery - Format a Microsoft JSON date? - Stack Overflow,, 13 September 2015, WEB,weblink Tales from the Evil Empire - Dates and JSON,, 13 September 2015, Other languages may have a different set of native types that must be serialized carefully to deal with this type of conversion.

Schema and metadata

JSON Schema

{{anchor|Schema}}JSON SchemaWEB,weblink JSON Schema and Hyper-Schema,, 13 September 2015, specifies a JSON-based format to define the structure of JSON data for validation, documentation, and interaction control. It provides a contract for the JSON data required by a given application, and how that data can be modified.JSON Schema is based on the concepts from XML Schema (XSD), but is JSON-based. As in XSD, the same serialization/deserialization tools can be used both for the schema and data; and is self-describing. It is specified in an Internet Draft at the IETF, currently in its 7th draft, which was released on March 18, 2018.WEB,weblink draft-handrews-json-schema-01 - JSON Schema: A Media Type for Describing JSON Documents,, 10 February 2019, 2018-03-19, There are several validators available for different programming languages,WEB,weblink JSON Schema Implementations,, 10 February 2019, each with varying levels of conformance.There is no standard file extension, but some have suggested .schema.json.WEB,weblink Json Schema file extension, Stack Overflow, Example JSON Schema (draft 4):{
"$schema": "",
"title": "Product",
"type": "object",
"required": ["id", "name", "price"],
"properties": {
"id": {
"type": "number",
"description": "Product identifier"
"name": {
"type": "string",
"description": "Name of the product"
"price": {
"type": "number",
"minimum": 0
"tags": {
"type": "array",
"items": {
"type": "string"
"stock": {
"type": "object",
"properties": {
"warehouse": {
"type": "number"
"retail": {
"type": "number"
}The JSON Schema above can be used to test the validity of the JSON text below:{
"id": 1,
"name": "Foo",
"price": 123,
"tags": [
"stock": {
"warehouse": 300,
"retail": 20

MIME type

The official MIME type for JSON text is "application/json",WEB,weblink Media Types,, 13 September 2015, and most modern implementations have adopted this.The (unofficial) MIME type "text/json" or the content-type "text/javascript" also get legacy support by many service providers, browsers, servers, web applications, libraries, frameworks, and APIs. Notable examples include the Google Search API,WEB,weblink Handle application/json & text/json by benschwarz · Pull Request #2 · mislav/faraday-stack, GitHub, 13 September 2015, Yahoo!,WEB,weblink Yahoo!, JavaScript, and JSON, ProgrammableWeb, 13 September 2015, 2005-12-16, Flickr, Facebook API,WEB,weblink Make JSON requests allow text/javascript content by jakeboxer · Pull Request #148 · AFNetworking/AFNetworking, GitHub, 13 September 2015, Lift framework,WEB,weblink lift/Req.scala at master · lift/lift · GitHub, GitHub, 13 September 2015, Dojo Toolkit 0.4,WEB,weblink BrowserIO.js in legacy/branches/0.4/src/io – Dojo Toolkit,, 13 September 2015, etc.



JSON-RPC is a remote procedure call (RPC) protocol built on JSON, as a replacement for XML-RPC or SOAP. It is a simple protocol that defines only a handful of data types and commands. JSON-RPC lets a system send notifications (information to the server that does not require a response) and multiple calls to the server that can be answered out of order.Example of a JSON-RPC 2.0 request and response using positional parameters.--> {"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1}', the representation is often about the same size as JSON or just a little larger. However, an XML attribute can only have a single value and each attribute can appear at most once on each element.XML separates "data" from "metadata" (via the use of elements and attributes), while JSON does not have such a concept.Another key difference is the addressing of values. JSON has objects with a simple "key" → "value" mapping, whereas in XML addressing happens on "nodes", which all receive a unique ID via the XML processor. Additionally, the XML standard defines a common attribute "xml:id", that can be used by the user, to set an ID explicitly.XML values are strings of characters, with no built-in type safety. XML has the concept of schema, that permits strong typing, user-defined types, predefined tags, and formal structure, allowing for formal validation of an XML stream. JSON has strong typing built-in, and has a similar schema concept in JSON Schema.XML supports comments, but JSON does not.BOOK, Saternos, Casimir, Client-server web apps with Javascript and Java, 2014, 9781449369316, 45,


JSON sample

"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021"
"phoneNumbers": [
"type": "home",
"number": "212 555-1234"
"type": "fax",
"number": "646 555-4567"
"sex": {
"type": "male"
}Both of the following examples carry the same kind of information as the JSON example above in different ways. More JSON Examples.

YAML sample

The JSON text above is also entirely valid YAML. YAML also offers an alternative syntax intended to be more human-accessible by replacing nested delimiters like {}, [], and " marks with indentation.firstName: JohnlastName: Smithage: 25address:
streetAddress: 21 2nd Street
city: New York
state: NY
postalCode: '10021'
phoneNumbers: - type: home
number: 212 555-1234
- type: fax
number: 646 555-4567
type: male

XML samples

Note that the XML examples below don't encode the data type (e.g. that age is a number), and would need something like a schema to encode the same information as the JSON example above does as is.

21 2nd Street
New York

212 555-1234

646 555-4567

The properties can also be serialized using attributes instead of tags:

See also

  • JSON streaming – on delimiting JSON in stream protocols
  • Comparison of data serialization formats
  • Related formats
    • GeoJSON – an open format for encoding a variety of geographic data structures
    • JSON-LD – JavaScript object notation for linked data, a W3C recommendation
    • JSON-RPC – remote procedure call protocol encoded in JSON
    • JsonML – markup language used to map between XML and JSON
    • JSONP – JSON with Padding, a pattern of usage commonly employed when retrieving JSON across domains
    • S-expression – the comparable LISP format for trees as text.
    • SOAPjr – a hybrid of SOAP and JR (JSON-RPC)
  • Related binary encodings
    • BSON – with data types of specific interest to MongoDB
    • CBOR – loosely based on JSON
    • MessagePack – with data types loosely corresponding with JSON's
    • Smile – based on JSON
    • UBJSON – binary format directly imitating JSON
    • EXI4JSON (EXI for JSON) – representation by means of the Efficient XML Interchange (EXI) standard
  • Implementations:
    • Jackson – JSON processor for Java





External links

{{Sister project links |wikt=JSON |commons=Category:JavaScript Object Notation |b=JavaScript/Handling JSON |n=no |q=no |s=no |v=no}}
  • {{official websiteweblink}}
  • WEB,weblink ECMA-404 JSON Data Interchange Format, ECMA Int'l,
  • {{IETF RFC|8259}}, JSON Data Interchange Format
{{Data Exchange}}{{Authority control}}

- content above as imported from Wikipedia
- "JSON#Native encoding and decoding in browsers>native JSON" does not exist on GetWiki (yet)
- time: 12:45am EDT - Fri, Aug 23 2019
[ this remote article is provided by Wikipedia ]
LATEST EDITS [ see all ]
Eastern Philosophy
History of Philosophy
M.R.M. Parrott