diff options
| author | Ryan Johnson <rjohnson@mozilla.com> | 2021-04-29 16:16:42 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-29 16:16:42 -0700 |
| commit | 95aca4b4d8fa62815d4bd412fff1a364f842814a (patch) | |
| tree | 5e57661720fe9058d5c7db637e764800b50f9060 /files/it/web/javascript/reference/global_objects/json/index.html | |
| parent | ee3b1c87e3c8e72ca130943eed260ad642246581 (diff) | |
| download | translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.tar.gz translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.tar.bz2 translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.zip | |
remove retired locales (#699)
Diffstat (limited to 'files/it/web/javascript/reference/global_objects/json/index.html')
| -rw-r--r-- | files/it/web/javascript/reference/global_objects/json/index.html | 244 |
1 files changed, 0 insertions, 244 deletions
diff --git a/files/it/web/javascript/reference/global_objects/json/index.html b/files/it/web/javascript/reference/global_objects/json/index.html deleted file mode 100644 index caa08b766f..0000000000 --- a/files/it/web/javascript/reference/global_objects/json/index.html +++ /dev/null @@ -1,244 +0,0 @@ ---- -title: JSON -slug: Web/JavaScript/Reference/Global_Objects/JSON -tags: - - JSON - - JavaScript - - NeedsTranslation - - Object - - Reference - - TopicStub - - polyfill -translation_of: Web/JavaScript/Reference/Global_Objects/JSON ---- -<div>{{JSRef}}</div> - -<p>The <strong><code>JSON</code></strong> object contains methods for parsing <a class="external" href="http://json.org/">JavaScript Object Notation</a> ({{glossary("JSON")}}) and converting values to JSON. It can't be called or constructed, and aside from its two method properties it has no interesting functionality of its own.</p> - -<h2 id="Description">Description</h2> - -<h3 id="JavaScript_Object_Notation">JavaScript Object Notation</h3> - -<p>JSON is a syntax for serializing objects, arrays, numbers, strings, booleans, and {{jsxref("null")}}. It is based upon JavaScript syntax but is distinct from it: some JavaScript is not JSON, and some JSON is not JavaScript. See also <a href="http://timelessrepo.com/json-isnt-a-javascript-subset">JSON: The JavaScript subset that isn't</a>.</p> - -<table> - <caption>JavaScript and JSON differences</caption> - <thead> - <tr> - <th scope="col">JavaScript type</th> - <th scope="col">JSON differences</th> - </tr> - </thead> - <tbody> - <tr> - <td>Objects and Arrays</td> - <td>Property names must be double-quoted strings; trailing commas are forbidden.</td> - </tr> - <tr> - <td>Numbers</td> - <td>Leading zeros are prohibited; a decimal point must be followed by at least one digit.</td> - </tr> - <tr> - <td>Strings</td> - <td> - <p>Only a limited sets of characters may be escaped; certain control characters are prohibited; the Unicode line separator (<a href="http://unicode-table.com/en/2028/">U+2028</a>) and paragraph separator (<a href="http://unicode-table.com/en/2029/">U+2029</a>) characters are permitted; strings must be double-quoted. See the following example where {{jsxref("JSON.parse()")}} works fine and a {{jsxref("SyntaxError")}} is thrown when evaluating the code as JavaScript:</p> - - <pre class="brush: js"> -var code = '"\u2028\u2029"'; -JSON.parse(code); // works fine -eval(code); // fails -</pre> - </td> - </tr> - </tbody> -</table> - -<p>The full JSON syntax is as follows:</p> - -<pre><var>JSON</var> = <strong>null</strong> - <em>or</em> <strong>true</strong> <em>or</em> <strong>false</strong> - <em>or</em> <var>JSONNumber</var> - <em>or</em> <var>JSONString</var> - <em>or</em> <var>JSONObject</var> - <em>or</em> <var>JSONArray</var> - -<var>JSONNumber</var> = <strong>-</strong> <var>PositiveNumber</var> - <em>or</em> <var>PositiveNumber</var> -<var>PositiveNumber</var> = DecimalNumber - <em>or</em> <var>DecimalNumber</var> <strong>.</strong> <var>Digits</var> - <em>or</em> <var>DecimalNumber</var> <strong>.</strong> <var>Digits</var> <var>ExponentPart</var> - <em>or</em> <var>DecimalNumber</var> <var>ExponentPart</var> -<var>DecimalNumber</var> = <strong>0</strong> - <em>or</em> <var>OneToNine</var> <var>Digits</var> -<var>ExponentPart</var> = <strong>e</strong> <var>Exponent</var> - <em>or</em> <strong>E</strong> <var>Exponent</var> -<var>Exponent</var> = <var>Digits</var> - <em>or</em> <strong>+</strong> <var>Digits</var> - <em>or</em> <strong>-</strong> <var>Digits</var> -<var>Digits</var> = <var>Digit</var> - <em>or</em> <var>Digits</var> <var>Digit</var> -<var>Digit</var> = <strong>0</strong> through <strong>9</strong> -<var>OneToNine</var> = <strong>1</strong> through <strong>9</strong> - -<var>JSONString</var> = <strong>""</strong> - <em>or</em> <strong>"</strong> <var>StringCharacters</var> <strong>"</strong> -<var>StringCharacters</var> = <var>StringCharacter</var> - <em>or</em> <var>StringCharacters</var> <var>StringCharacter</var> -<var>StringCharacter</var> = any character - <em>except</em> <strong>"</strong> <em>or</em> <strong>\</strong> <em>or</em> U+0000 through U+001F - <em>or</em> <var>EscapeSequence</var> -<var>EscapeSequence</var> = <strong>\"</strong> <em>or</em> <strong>\/</strong> <em>or</em> <strong>\\</strong> <em>or</em> <strong>\b</strong> <em>or</em> <strong>\f</strong> <em>or</em> <strong>\n</strong> <em>or</em> <strong>\r</strong> <em>or</em> <strong>\t</strong> - <em>or</em> <strong>\u</strong> <var>HexDigit</var> <var>HexDigit</var> <var>HexDigit</var> <var>HexDigit</var> -<var>HexDigit</var> = <strong>0</strong> through <strong>9</strong> - <em>or</em> <strong>A</strong> through <strong>F</strong> - <em>or</em> <strong>a</strong> through <strong>f</strong> - -<var>JSONObject</var> = <strong>{</strong> <strong>}</strong> - <em>or</em> <strong>{</strong> <var>Members</var> <strong>}</strong> -<var>Members</var> = <var>JSONString</var> <strong>:</strong> <var>JSON</var> - <em>or</em> <var>Members</var> <strong>,</strong> <var>JSONString</var> <strong>:</strong> <var>JSON</var> - -<var>JSONArray</var> = <strong>[</strong> <strong>]</strong> - <em>or</em> <strong>[</strong> <var>ArrayElements</var> <strong>]</strong> -<var>ArrayElements</var> = <var>JSON</var> - <em>or</em> <var>ArrayElements</var> <strong>,</strong> <var>JSON</var> -</pre> - -<p>Insignificant whitespace may be present anywhere except within a <code><var>JSONNumber</var></code> (numbers must contain no whitespace) or <code><var>JSONString</var></code> (where it is interpreted as the corresponding character in the string, or would cause an error). The tab character (<a href="http://unicode-table.com/en/0009/">U+0009</a>), carriage return (<a href="http://unicode-table.com/en/000D/">U+000D</a>), line feed (<a href="http://unicode-table.com/en/000A/">U+000A</a>), and space (<a href="http://unicode-table.com/en/0020/">U+0020</a>) characters are the only valid whitespace characters.</p> - -<h2 id="Methods">Methods</h2> - -<dl> - <dt>{{jsxref("JSON.parse()")}}</dt> - <dd>Parse a string as JSON, optionally transform the produced value and its properties, and return the value.</dd> - <dt>{{jsxref("JSON.stringify()")}}</dt> - <dd>Return a JSON string corresponding to the specified value, optionally including only certain properties or replacing property values in a user-defined manner.</dd> -</dl> - -<h2 id="Polyfill">Polyfill</h2> - -<p>The <code>JSON</code> object is not supported in older browsers. You can work around this by inserting the following code at the beginning of your scripts, allowing use of <code>JSON</code> object in implementations which do not natively support it (like Internet Explorer 6).</p> - -<p>The following algorithm is an imitation of the native <code>JSON</code> object:</p> - -<pre class="brush: js">if (!window.JSON) { - window.JSON = { - parse: function(sJSON) { return eval('(' + sJSON + ')'); }, - stringify: (function () { - var toString = Object.prototype.toString; - var isArray = Array.isArray || function (a) { return toString.call(a) === '[object Array]'; }; - var escMap = {'"': '\\"', '\\': '\\\\', '\b': '\\b', '\f': '\\f', '\n': '\\n', '\r': '\\r', '\t': '\\t'}; - var escFunc = function (m) { return escMap[m] || '\\u' + (m.charCodeAt(0) + 0x10000).toString(16).substr(1); }; - var escRE = /[\\"\u0000-\u001F\u2028\u2029]/g; - return function stringify(value) { - if (value == null) { - return 'null'; - } else if (typeof value === 'number') { - return isFinite(value) ? value.toString() : 'null'; - } else if (typeof value === 'boolean') { - return value.toString(); - } else if (typeof value === 'object') { - if (typeof value.toJSON === 'function') { - return stringify(value.toJSON()); - } else if (isArray(value)) { - var res = '['; - for (var i = 0; i < value.length; i++) - res += (i ? ', ' : '') + stringify(value[i]); - return res + ']'; - } else if (toString.call(value) === '[object Object]') { - var tmp = []; - for (var k in value) { - if (value.hasOwnProperty(k)) - tmp.push(stringify(k) + ': ' + stringify(value[k])); - } - return '{' + tmp.join(', ') + '}'; - } - } - return '"' + value.toString().replace(escRE, escFunc) + '"'; - }; - })() - }; -} -</pre> - -<p>More complex well-known <a class="external" href="http://remysharp.com/2010/10/08/what-is-a-polyfill/">polyfills</a> for the <code>JSON</code> object are <a class="link-https" href="https://github.com/douglascrockford/JSON-js">JSON2</a> and <a class="external" href="http://bestiejs.github.com/json3">JSON3</a>.</p> - -<h2 id="Specifications">Specifications</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specification</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.12', 'JSON')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-json-object', 'JSON')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoDesktop("1.9.1")}}</td> - <td>{{CompatIE("8.0")}}</td> - <td>{{CompatOpera("10.5")}}</td> - <td>{{CompatSafari("4.0")}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoMobile("1.0")}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="See_also">See also</h2> - -<ul> - <li>{{jsxref("Date.prototype.toJSON()")}}</li> -</ul> |
