[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/JSON [Back]  [Original]

JSON - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

JSON

Baseline Widely available *

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

* Some parts of this feature may have varying levels of support.

JSON JavaScript (JavaScript Object Notation JSON) JSON. , .

In this article

JavaScript

JSON , , , null. JavaScript, : JavaScript JSON, JSON JavaScript. JSON: JavaScript, ( ).

JavaScript JSON
JavaScript JSON
, ; .
; .

; ; (U+2028) (U+2029); . , JSON.parse() , JavaScript SyntaxError:

js
var code = '"\u2028\u2029"';
JSON.parse(code); // 
eval(code); // 

JSON:

JSON = null
    or true or false
    or JSONNumber
    or JSONString
    or JSONObject
    or JSONArray

JSONNumber = - PositiveNumber
          or PositiveNumber
PositiveNumber = DecimalNumber
              or DecimalNumber . Digits
              or DecimalNumber . Digits ExponentPart
              or DecimalNumber ExponentPart
DecimalNumber = 0
             or OneToNine Digits
ExponentPart = e Exponent
            or E Exponent
Exponent = Digits
        or + Digits
        or - Digits
Digits = Digit
      or Digits Digit
Digit = 0 through 9
OneToNine = 1 through 9

JSONString = ""
          or " StringCharacters "
StringCharacters = StringCharacter
                or StringCharacters StringCharacter
StringCharacter = any character
                  except " or \ or U+0000 through U+001F
               or EscapeSequence
EscapeSequence = \" or \/ or \\ or \b or \f or \n or \r or \t
              or \u HexDigit HexDigit HexDigit HexDigit
HexDigit = 0 through 9
        or A through F
        or a through f

JSONObject = { }
          or { Members }
Members = JSONString : JSON
       or Members , JSONString : JSON

JSONArray = [ ]
         or [ ArrayElements ]
ArrayElements = JSON
             or ArrayElements , JSON

, JSON ( ) JSON ( ). (U+0009), (U+000D), (U+000A) , , (U+0020).

JSON.parse()

JSON, .

JSON.stringify()

JSON, , .

JSON . , , JSON , (, Internet Explorer 6).

JSON:

js
if (!window.JSON) {
  window.JSON = {
    parse: function (sJSON) {
      return eval("(" + sJSON + ")");
    },
    stringify: function (vContent) {
      if (vContent instanceof Object) {
        var sOutput = "";
        if (vContent.constructor === Array) {
          for (
            var nId = 0;
            nId < vContent.length;
            sOutput += this.stringify(vContent[nId]) + ",", nId++
          );
          return "[" + sOutput.substr(0, sOutput.length - 1) + "]";
        }
        if (vContent.toString !== Object.prototype.toString) {
          return '"' + vContent.toString().replace(/"/g, "\\$&") + '"';
        }
        for (var sProp in vContent) {
          sOutput +=
            '"' +
            sProp.replace(/"/g, "\\$&") +
            '":' +
            this.stringify(vContent[sProp]) +
            ",";
        }
        return "{" + sOutput.substr(0, sOutput.length - 1) + "}";
      }
      return typeof vContent === "string"
        ? '"' + vContent.replace(/"/g, "\\$&") + '"'
        : String(vContent);
    },
  };
}

JSON JSON2 JSON3.

Specification
ECMAScript 2027 LanguageSpecification
# sec-json-object


Web Proxy Viewer  |  New URL  |  Original Page