[31] [DFN[[RUBY[[[JSON]]][ジェイソン]]]] ([DFN[JavaScript Object Notation]] / [DFN[JavaScript オブジェクト記法]])
は、 [[JavaScript]] における[[オブジェクト・リテラル]]の[[部分集合]]によって[[オブジェクト]]や[[配列]]を表記するデータ交換書式です。
[[JavaScript]] を始め数多くの[[言語]]で[[ライブラリー]]が整備されており、
汎用的な[[データ構造]]の交換形式として広く用いられています。
[30]
[CITE@en[JSON]] ([TIME[2011-07-09 12:55:13 +09:00]] 版)
>JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.
* 仕様書
- [3] [CITE@en[RFC 4627 - The application/json Media Type for JavaScript Object Notation (JSON)]]
- [34] [CITE[Annotated ES5]]
-- [35] [CSECTION@en[5.1.5 The JSON Grammar]]
-- [36] '''[CSECTION@en[15.12 The JSON Object]] '''
* データ型
[37] [[JSON]] では以下の[[データ型]]を表現できます [SRC[>>3 1.]]。
- [38] [RUBYB[[[プリミティブ型]]]@en[primitive types]]
-- [39] [RUBYB[[[文字列]]]@en[string]]
-- [40] [RUBYB[[[数値]]]@en[number]]
-- [41] [[boolean]]
-- [42] [[null]]
- [43] [RUBYB[[[構造化型]]]@en[structured types]]
-- [44] [RUBYB[[[オブジェクト]]]@en[object]]
-- [45] [RUBYB[[[配列]]]@en[array]]
* 不正な JSON
- [22] [[JSONP]] が [[JSON]] として扱われることがあります。
- [23] [[オブジェクト]]の[[特性名]]を表す[[文字列リテラル]]が [CODE(char)[[["]]]] で括られないことがあります。
- [24] [[JSON]] の前に「[CODE(JS)[[[var]] name = ]]」のような[[文字列]]がつくことがあります。
- [25] [[YAML]] の [[serializer]] によって実際には [[JSON]] ではないものが [[JSON]] であるとして出力されることがあります。
* JavaScript との互換性
[28] [CITE[JSON: The JavaScript subset that isn't — Timeless]]
([TIME[2011-05-16 04:05:34 +09:00]] 版)
[27] [CITE[JSON::XS - search.cpan.org]] ([TIME[2011-04-15 12:50:01 +09:00]] 版)
>One of the problems is that U+2028 and U+2029 are valid characters inside JSON strings, but are not allowed in ECMAscript string literals
>Another problem is that some javascript implementations reserve some property names for their own purposes (which probably makes them non-ECMAscript-compliant). For example, Iceweasel reserves the __proto__ property name for it's own purposes.
* YAML との互換性
[26] [[JSON]] は [[YAML]] の[[部分集合]]であるとの主張は'''嘘'''とされています。
;; [CITE[JSON::XS - search.cpan.org]] ([TIME[2011-04-15 12:50:01 +09:00]] 版)
* [CODE(JS)@en[JSON]] オブジェクト (JavaScript)
- [CODE(JS)@en[[[JSON.parse]]]]
- [CODE(JS)@en[[[JSON.stringify]]]]
** 歴史
[9] [CITE[Re: Native JSON parsing API]] ([[Henri Sivonen]] 著, [TIME[2008-06-16 06:12:12 +09:00]] 版)
>
The JSON parsers I've used in non-browser contexts have been Draconian
and incompatible with existing content such as output from
del.icio.us, which can contain escaped single quotes, which isn't
allowed in proper JSON.
[10]
[CITE[JSON Serialization (was Re: ES4 draft: Name)]] ([TIME[2008-04-01 12:34:49 +09:00]] 版)
[11] [CITE[Re: Native JSON parsing API]] ([[Maciej Stachowiak ]] 著, [TIME[2008-06-14 08:43:00 +09:00]] 版)
>Native JSON parsing is being considered for the next versions of
ECMAScript (the 3.1 and 4 versions). It seems like a better fit there
than in HTML5. If it ends up not being added to ECMAScript, I would
propose it as a standalone spec for the W3C Web Apps WG.
[12] [CITE@en[es3.1:json_support '''['''ES4 Wiki''']''']] ([TIME[2008-12-20 11:20:05 +09:00]] 版)
[14] [CITE@ja-jp[2008/9/10 - Internet Explorer 8 のネイティブ JSON]] ([TIME[2009-02-02 22:11:29 +09:00]] 版)
[15] [CITE@en-us[Firefox 3.1 for developers - MDC]] ([TIME[2009-02-08 18:25:06 +09:00]] 版)
>ネイティブ JSON の DOM バインディング( bug 408838 ) 。
** 実装
[13] [CITE@en-us[JSON - MDC]] ([TIME[2009-02-02 22:06:53 +09:00]] 版)
[16] [CITE[JSON、8進数 - 素人がプログラミングを勉強するブログ]] ([TIME[2009-06-28 10:12:45 +09:00]] 版)
>まず、0123のように、0以外で先頭が0の数値はJSONとして不正である。
>例えばJSON.parse("0123")を評価すると、IE8とWebKit(r45311)ではSyntaxErrorが投げられる。
>
Firefox(20090617のナイトリー)では、123になる。
>
http://www.json.org/json2.js:json2.jsとGoogle Chrome(3.0.191)では、83になる。
[18] [CITE@en-us[JSON - MDC]]
([TIME[2009-10-18 14:43:23 +09:00]] 版)
* メモ
[1]
[CITE[Introducing JSON]]
> [CODE[JSON]] (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.
;; [29] リンク切れ [TIME[2011-08-24T11:10:03.000Z]]
[2]
''Semantic Interpretation for Speech Recognition (SISR) Version 1.0''
([[名無しさん]] [WEAK[2006-01-19 03:31:05 +00:00]])
[4]
>>3 明記されていないけど [[BOM]] は使えないということでおk?
([[名無しさん]])
[5]
不適合文書の扱いも明記されていないけど、構文解析器は不適合も処理して'''構わない'''ことになっているから、
適当に理解するなりはじくなりでおk?
([[名無しさん]])
[6]
[[サロゲート・ペア]]の片割れだけが escape されている場合は >>5?
([[名無しさん]])
[7]
[CITE@ja-JP[Matzにっき(2007-04-16)]] ([[Yukihiro -matz- Matsumoto]] 著, [CODE[2007-04-23 23:58:26 +09:00]] 版)
([[名無しさん]] [WEAK[2007-05-05 03:25:51 +00:00]])
[8]
[CITE@en[JSONLint - The JSON Validator.]] ([TIME[2008-06-22 12:32:25 +09:00]] 版)
[17] [CITE[IRC logs: freenode / #whatwg / 20090906]]
([TIME[2009-10-17 22:08:59 +09:00]] 版)
;; [33] [[JSON]] の[[構文解析]]における互換性について。 [[RFC]] は非標準の拡張を理解することを認めている。
[[ES5]] はより厳密に定義している。古い案では[[注釈]]を認めていたが、
非標準の[[指令]]の埋込みに使われるようになったため、結局認めないことになった。
[19] [CITE[as3corelib の JSON.decode() をいい加減な JSON に対応させる - てっく煮ブログ]]
([TIME[2010-01-01 12:15:16 +09:00]] 版)
[20] [CITE[IRC logs: freenode / #whatwg / 20100104]]
([TIME[2010-01-06 08:11:05 +09:00]] 版)
;; [32] [[JSON]] の[[文字符号化]]について。