JSON
Dan Tobias (Talk | contribs) (→Utilities) |
(→Sample files) |
||
(34 intermediate revisions by 5 users not shown) | |||
Line 2: | Line 2: | ||
|formattype=electronic | |formattype=electronic | ||
|subcat=Serialization | |subcat=Serialization | ||
+ | |thiscat=JSON | ||
|extensions={{ext|json}} | |extensions={{ext|json}} | ||
|mimetypes={{mimetype|application/json}} | |mimetypes={{mimetype|application/json}} | ||
+ | |pronom={{PRONOM|fmt/817}} | ||
+ | |locfdd={{LoCFDD|fdd000381}} | ||
+ | |wikidata={{wikidata|Q2063}} | ||
}} | }} | ||
− | '''JSON''' (JavaScript Object Notation) is widely used by web applications to communicate between a | + | '''JSON''' (JavaScript Object Notation) is widely used by web applications, APIs, mobile apps, and other programs to communicate between different systems (such as between a client and server), and as a save format for data storage. While it is named after [[JavaScript]], there are libraries for many other programming and scripting languages to let them use this format as well. It is used as the basis of a number of specialized formats; the geospatial format [[GeoJSON]] is based on JSON, as is the remote-procedure-call protocol [[JSON-RPC]] and the [[JSON-LD]] linked-data format. The IBM standard of [[JSONx]] is an [[XML]] implementation of JSON. [[I-JSON]] is a restricted profile of JSON for Internet use developed by the IETF. [[JSON Web Tokens]], [[JSON Web Encryption]], and [[JSON Web Signatures]] are JSON-based formats for security-related functions. |
== Format == | == Format == | ||
Line 17: | Line 21: | ||
* ''true'', ''false'', or ''nil'' are permitted as typeless values. (Other formats and programming languages may put these into boolean or pointer types.) | * ''true'', ''false'', or ''nil'' are permitted as typeless values. (Other formats and programming languages may put these into boolean or pointer types.) | ||
− | * '''object''': An associative array consisting of names and values, where the name and value are separated by a colon (:), the name/value pairs are separated by commas, and the whole object is surrounded by curly braces {}. The name is a (double-quoted) string, and the value can be any of the data types in JSON including another object. There is no inherent ordering to the values of an object. (Other formats and programming languages may call these ''associative arrays'', ''hashes'', or ''dictionaries''.) | + | * '''object''': An associative array consisting of names and values, where the name and value are separated by a colon (:), the name/value pairs are separated by commas, and the whole object is surrounded by curly braces {}. The name is a (double-quoted) string, and the value can be any of the data types in JSON including another object. There is no inherent ordering to the values of an object. (Other formats and programming languages may call these ''associative arrays'', ''hashes'', ''maps'', or ''dictionaries''.) |
− | * '''array''': An ordered collection of values, which can each be any of the JSON data types, and are separated by commas and surrounded by square brackets []. (Other formats and programming languages may call these ''arrays'' or ''lists''.) | + | * '''array''': An ordered collection of values, which can each be any of the JSON data types, and are separated by commas and surrounded by square brackets []. (Other formats and programming languages may call these ''arrays'', ''collections'', or ''lists''.) |
== JSONP == | == JSONP == | ||
'''JSONP''' is a variant of JSON, "padded" with additional [[JavaScript]] code to permit the entire data set to be a valid piece of JS code able to be imported via a <code><script></code> statement for execution. Generally the extra code will be a function call encompassing the JSON data as its parameter, but sometimes it will be a variable assignment or other code. This gets around security restrictions in browser implementations of JavaScript which limit use of external data loaded from other sites (script statements can reference outside URLs), making it both very powerful and very dangerous if misused. | '''JSONP''' is a variant of JSON, "padded" with additional [[JavaScript]] code to permit the entire data set to be a valid piece of JS code able to be imported via a <code><script></code> statement for execution. Generally the extra code will be a function call encompassing the JSON data as its parameter, but sometimes it will be a variable assignment or other code. This gets around security restrictions in browser implementations of JavaScript which limit use of external data loaded from other sites (script statements can reference outside URLs), making it both very powerful and very dangerous if misused. | ||
+ | |||
+ | Largely, JSONP has been superseded by the wider browser support for JSON and introduction of [https://en.wikipedia.org/wiki/JSONP CORS]. | ||
+ | |||
+ | == JSON Pointer == | ||
+ | |||
+ | JSON Pointer (described in RFC 6901) is a syntax for referencing a specific value within a JSON document. It consists of a string with hierarchical elements separated by slashes (/), each element being a reference to an element of the JSON document (e.g., the label name of an object element or the numerical index of an array element). Thus, "/foo/0" represents the first (zeroth) element of the array which is at the label "foo" of a parent object. Escape sequences ~1 and ~0 are used to represent a slash (/) and a tilde (~) respectively, with ~1 being processed first to avoid misparsing strings with "~01" (which represents "~1", not "/"). | ||
== See also == | == See also == | ||
+ | * [[CoffeeScript-Object-Notation]] | ||
+ | * [[Cursive Script Object Notation]] | ||
+ | * [[GeoJSON]] | ||
+ | * [[Hjson]] | ||
+ | * [[I-JSON]] | ||
+ | * [[JMESPath]] [http://jmespath.org/] | ||
* [[JSON API]] | * [[JSON API]] | ||
+ | * [[JSONata]] | ||
+ | * [[JSON-LD]] | ||
+ | * [[Jsonnet]] | ||
+ | * [[JSON Merge Patch]] (RFC 7396) | ||
+ | * [[JSON Patch]] | ||
+ | * [[JSON Pointer]] (RFC 6901) | ||
+ | * [[JSON-RPC]] | ||
+ | * [[JSON Table Schema]] | ||
+ | * [[JSON Type Definition]] | ||
+ | * [[JSONx]] | ||
+ | For formats based on JSON, see [[:Category:JSON based file formats]]. | ||
== Specs and schemas == | == Specs and schemas == | ||
Line 35: | Line 62: | ||
* RFC 4627 | * RFC 4627 | ||
− | == Sample | + | == Sample files == |
− | + | ||
* [http://parltrack.euwiki.org/dumps/ Data from European Parliament in JSON form] (Source: [http://parltrack.euwiki.org/ ParlTrack]) | * [http://parltrack.euwiki.org/dumps/ Data from European Parliament in JSON form] (Source: [http://parltrack.euwiki.org/ ParlTrack]) | ||
+ | * {{DexvertSamples|text/json}} | ||
== Utilities == | == Utilities == | ||
Line 54: | Line 81: | ||
* [[Wikipedia:JSONP|Wikipedia: JSONP]] | * [[Wikipedia:JSONP|Wikipedia: JSONP]] | ||
* [http://www.infoq.com/news/2013/04/JSON-Validation?utm_medium=referral&utm_source=t.co JSON Validation Roundup] | * [http://www.infoq.com/news/2013/04/JSON-Validation?utm_medium=referral&utm_source=t.co JSON Validation Roundup] | ||
− | * [http://www. | + | * [http://stackoverflow.com/questions/2669690/why-does-google-prepend-while1-to-their-json-responses Why does Google prepend while(1); to their JSON responses?] |
+ | * [http://www.w3.org/TR/csv2json/ Generating JSON from tabular data on the Web (W3C)] | ||
+ | * [http://seriot.ch/parsing_json.html Parsing JSON is a Minefield] - in test with 30 JSON parsers no two parsers showed the same behaviour | ||
+ | * [https://apifriends.com/api-management/why-json-won-over-xml/ Why JSON won over XML] | ||
+ | |||
+ | [[Category:Metaformats]] | ||
+ | [[Category:JSON based file formats]] |
Latest revision as of 15:02, 28 December 2023
JSON (JavaScript Object Notation) is widely used by web applications, APIs, mobile apps, and other programs to communicate between different systems (such as between a client and server), and as a save format for data storage. While it is named after JavaScript, there are libraries for many other programming and scripting languages to let them use this format as well. It is used as the basis of a number of specialized formats; the geospatial format GeoJSON is based on JSON, as is the remote-procedure-call protocol JSON-RPC and the JSON-LD linked-data format. The IBM standard of JSONx is an XML implementation of JSON. I-JSON is a restricted profile of JSON for Internet use developed by the IETF. JSON Web Tokens, JSON Web Encryption, and JSON Web Signatures are JSON-based formats for security-related functions.
Contents |
[edit] Format
JSON is a very simply-defined format for representing data in text-based form using a few simple types, including two "compound types" which can be nested:
- number: A decimal number, optionally including a decimal point or exponential notation. Leading zeroes are not allowed unless the only number before the decimal point is a single zero, or the number is equal to zero. (Other formats and programming languages may call these int, float, double, long, etc.)
- string: A string of (Unicode) characters surrounded by double quotes ("). The only characters not allowed directly (without escaping) are double quotes, backslashes, or control characters; a backslash can be used to precede a quote or backslash used as a character within the string, as well as \b for backspace, \f for formfeed, \n for newline, \r for carriage return, \t for tab, and \u followed by 4 hexadecimal digits for encoding any Unicode character in the 0000-FFFF range. (Other formats and programming languages may call these string or array of char).
- true, false, or nil are permitted as typeless values. (Other formats and programming languages may put these into boolean or pointer types.)
- object: An associative array consisting of names and values, where the name and value are separated by a colon (:), the name/value pairs are separated by commas, and the whole object is surrounded by curly braces {}. The name is a (double-quoted) string, and the value can be any of the data types in JSON including another object. There is no inherent ordering to the values of an object. (Other formats and programming languages may call these associative arrays, hashes, maps, or dictionaries.)
- array: An ordered collection of values, which can each be any of the JSON data types, and are separated by commas and surrounded by square brackets []. (Other formats and programming languages may call these arrays, collections, or lists.)
[edit] JSONP
JSONP is a variant of JSON, "padded" with additional JavaScript code to permit the entire data set to be a valid piece of JS code able to be imported via a <script>
statement for execution. Generally the extra code will be a function call encompassing the JSON data as its parameter, but sometimes it will be a variable assignment or other code. This gets around security restrictions in browser implementations of JavaScript which limit use of external data loaded from other sites (script statements can reference outside URLs), making it both very powerful and very dangerous if misused.
Largely, JSONP has been superseded by the wider browser support for JSON and introduction of CORS.
[edit] JSON Pointer
JSON Pointer (described in RFC 6901) is a syntax for referencing a specific value within a JSON document. It consists of a string with hierarchical elements separated by slashes (/), each element being a reference to an element of the JSON document (e.g., the label name of an object element or the numerical index of an array element). Thus, "/foo/0" represents the first (zeroth) element of the array which is at the label "foo" of a parent object. Escape sequences ~1 and ~0 are used to represent a slash (/) and a tilde (~) respectively, with ~1 being processed first to avoid misparsing strings with "~01" (which represents "~1", not "/").
[edit] See also
- CoffeeScript-Object-Notation
- Cursive Script Object Notation
- GeoJSON
- Hjson
- I-JSON
- JMESPath [1]
- JSON API
- JSONata
- JSON-LD
- Jsonnet
- JSON Merge Patch (RFC 7396)
- JSON Patch
- JSON Pointer (RFC 6901)
- JSON-RPC
- JSON Table Schema
- JSON Type Definition
- JSONx
For formats based on JSON, see Category:JSON based file formats.
[edit] Specs and schemas
- Official website (includes spec and links to libraries in many languages)
- JSON Schema
- ECMA-404
- RFC 4627
[edit] Sample files
[edit] Utilities
- Linter/Validator
- Quick JSON pretty reformatter / JSON-tidy
- gojson: A simple command-line tool for manipulating JSON for use in developing Go code (generates Go structures from JSON)
- Go package to encode/decode JSON
- jq: command line JSON processor
- PapaParse: in-browser conversions between CSV and JSON
- Textract: extract text from various document formats including JSON
[edit] Other links
- Wikipedia: JSON
- Wikipedia: JSONP
- JSON Validation Roundup
- Why does Google prepend while(1); to their JSON responses?
- Generating JSON from tabular data on the Web (W3C)
- Parsing JSON is a Minefield - in test with 30 JSON parsers no two parsers showed the same behaviour
- Why JSON won over XML