JSON/ru

This is an old revision of JSON/ru, edited by Prospero78su at . The current revision is 114659.

/* Объекты JSON */

Overview

JSON(JavaScript Object Notation) является формой представления данных, которая обеспечивает стандартизированный формат обмена данными, используя простой текст. Как следует из названия, форма представления основана на подмножестве языка программирования JavaScript; тем не менее, эта форма полностью не зависит от языка. Помимо того, что легко человеку читать и писать, форма данных также легка для машининного для разбора и генерации.

Также, по сравнению с XML, более удобна для восприятия человеком.

Объекты JSON

Объекты JSON являются не более чем наборами пар имя/значение, разделенных запятыми (которые часто называются члены), заключенные в фигурные скобки:

{"name1":value1, "name2":value2 ...}

To make it easier for humans to read and visualize, the name/value pairs are often listed vertically: Для того, чтобы придать человеческий вид, для чтения и наглядности, пары имя/значение часто перечисляются в столбик:

{
    "name1": value1,
    "name2": value2
}

The name is supposed to be a string in double quotes, while the value can be any of the following:

JSON objects can always be nested arbitrarily to create even more complex objects:

{"user":
    {	"userid": 1900,
        "username": "jsmith",
        "password": "secret",
        "groups": [ "admins", "users", "maintainers"]
    }
}

Valid JSON format

There are a few rules and guidelines that define the JSON syntax (see RFC 4627):

Implementations

JSON implementation is not very strict, and a lot of leeway is granted to the client application and/or parser to enforce the guidelines. As usual when writing code:

There are two main implementations of JSON:

The official JSON Specification syntax

This implementation adheres strictly to the RFC 4627 guidelines above and does not allow deviation from the specification.

The Javascript syntax

This implementation follows the implementation of the Javascript programming language and as such allows for a few deviations from the official specification. For example:

  1. allows un-quoted keys eg {name: "John Doe" }
  2. allows single quotes for keys and/or string values; and a liberal mix of single and double quotes eg {'name': "John Doe", "language":'Pascal'}
  3. allows trailing comma after the last member of an array and/or object eg {"keywords":["if","begin","for",], "IDEs":["Lazarus","fpIDE","MSEide"],}

See also