admin管理员组

文章数量:1033835

JSON5 格式标准 Data Exchange Format 官方文档 中英双语

Standard JSON5 标准 JSON5

1.0.0 / March 2018 1.0.0 / 三月 2018

The JSON5 Data Interchange FormatThe JSON5 数据交换格式

Abstract 摘要

The JSON5 Data Interchange Format is a proposed extension to JSON that aims to make it easier for humans to write and maintain by hand. It does this by adding some minimal syntax features directly from ECMAScript 5.1.JSON5 数据交换格式是一个提议的 JSON 扩展,旨在通过直接添加一些来自 ECMAScript 5.1 的最小语法特性,使人类更容易手动编写和维护。

1Introduction 1 介绍

The JSON5 Data Interchange Format (JSON5) is a superset of JSON that aims to alleviate some of the limitations of JSON by expanding its syntax to include some productions from ECMAScript 5.1.JSON5 数据交换格式(JSON5)是 JSON 的超集,旨在通过扩展其语法以包括一些来自 ECMAScript 5.1 的生产来缓解 JSON 的一些限制。

Similar to JSON, JSON5 can represent four primitive types (strings, numbers, Booleans, and null) and two structured types (objects and arrays).与 JSON 类似,JSON5 可以表示四种原始类型(字符串、数字、布尔值和 null)以及两种结构化类型(对象和数组)。

A string is a sequence of zero or more Unicode characters. Note that this citation references the latest version of Unicode rather than a specific release. It is not expected that future changes in the Unicode specification will impact the syntax of JSON5.字符串是由零个或多个 Unicode 字符组成的序列。请注意,此引用引用的是 Unicode 的最新版本,而不是特定版本。预计 Unicode 规范的未来变化不会影响 JSON5 的语法。

An object is an unordered collection of zero or more name/value pairs, where a name is a string or identifier and a value is a string, number, Boolean, null, object, or array.对象是一个无序集合,包含零个或多个键值对,其中键是一个字符串或标识符,值是字符串、数字、布尔值、null、对象或数组。

An array is an ordered sequence of zero or more values.数组是一个有序的值序列。

1.1Summary of Features 1.1 功能概述

The following ECMAScript 5.1 features, which are not supported in JSON, have been extended to JSON5.以下 ECMAScript 5.1 特性,这些特性在 JSON 中不受支持,已经被扩展到 JSON5 中。

Objects 对象

  • Object keys may be an ECMAScript 5.1 IdentifierName.对象的键可以是 ECMAScript 5.1 的标识符名称。
  • Objects may have a single trailing comma.对象可以有单个尾随逗号。

Arrays 数组

  • Arrays may have a single trailing comma.数组可以有单个尾随逗号。

Strings 字符串

  • Strings may be single quoted.字符串可以使用单引号。
  • Strings may span multiple lines by escaping new line characters.字符串可以通过转义换行符跨越多行。
  • Strings may include character escapes.字符串可以包含字符转义。

Numbers 数字

  • Numbers may be hexadecimal.数字可以是十六进制。
  • Numbers may have a leading or trailing decimal point.数字可以有一个前导或尾随的小数点。
  • Numbers may be IEEE 754 positive infinity, negative infinity, and NaN.数字可以是 IEEE 754 的正无穷、负无穷和 NaN。
  • Numbers may begin with an explicit plus sign.数字可以以显式的加号开头。

Comments 评论

  • Single and multi-line comments are allowed.允许单行和多行注释。

White Space 空白字符

  • Additional white space characters are allowed.允许额外的空白字符。

1.2Short Example 1.2 简例

Example (Informative) 示例(信息性)

代码语言:javascript代码运行次数:0运行复制
{
  // comments
  unquoted: 'and you can quote me on that',
  singleQuotes: 'I can use "double quotes" here',
  lineBreaks: "Look, Mom! \
No \\n's!",
  hexadecimal: 0xdecaf,
  leadingDecimalPoint: .8675309, andTrailing: 8675309.,
  positiveSign: +1,
  trailingComma: 'in objects', andIn: ['arrays',],
  "backwardsCompatible": "with JSON",
}

2Values 2 值

A JSON5 value must be an object, array, string, or number, or one of the three literal names true, false, or null.JSON5 值必须是一个对象、数组、字符串、数字,或者是三个字面量名称之一: true 、 false 或 null 。

JSON5Value: JSON5 值:JSON5Null JSON5 空值JSON5Boolean JSON5 布尔值JSON5String JSON5 字符串JSON5Number JSON5 数字JSON5Object JSON5 对象JSON5Array JSON5 数组# 3Objects 3 个对象

An object structure is represented as a pair of curly brackets surrounding zero or more name/value pairs (or members). A name is a string or identifier. A single colon comes after each name, separating the name from the value. A single comma separates a value from a following name. A single comma may follow the name/value pair. The names within an object should be unique.对象结构用一对花括号表示,其中包含零个或多个名称/值对(或成员)。名称是一个字符串或标识符。每个名称之后跟一个单冒号,将名称与值分开。一个值之后跟一个单逗号,与后面的名称分开。名称/值对之后可以跟一个单逗号。对象内的名称应该是唯一的。

JSON5Object: JSON5 对象:{}{JSON5MemberList,opt} { JSON5 成员列表, 选择}JSON5MemberList: JSON5 成员列表:JSON5Member JSON5 成员JSON5MemberList,JSON5MemberJSON5 成员列表, JSON5 成员JSON5Member: JSON5 成员:JSON5MemberName:JSON5ValueJSON5 成员名称: JSON5 值JSON5MemberName: JSON5 成员名称:JSON5Identifier JSON5 标识符JSON5String JSON5 字符串An object whose names are all unique is interoperable in the sense that all software implementations receiving that object will agree on the name-value mappings. When the names within an object are not unique, the behavior of software that receives such an object is unpredictable. Implementations may report the last name/value pair only, report an error or fail to parse the object, or report all of the name/value pairs, including duplicates.一个名称全部唯一的对象在互操作性方面是可行的,即所有接收该对象的软件实现都将同意名称-值映射。当对象内的名称不唯一时,接收此类对象的软件的行为是不可预测的。实现可能只报告最后一个名称/值对,报告错误或无法解析对象,或者报告所有名称/值对,包括重复项。

Implementations may make the ordering of object members visible to calling software. Implementations whose behavior does not depend on member ordering will be interoperable in the sense that they will not be affected by this.实现可能将对象成员的顺序对调用软件可见。那些行为不依赖于成员顺序的实现将在互操作性方面是可行的,即它们将不会受到影响。

Example (Informative) 示例(信息性)

代码语言:javascript代码运行次数:0运行复制
// An empty object
{}

// An object with two properties
// and a trailing comma
{
    width: 1920,
    height: 1080,
}

// Objects can be nested
{
    image: {
        width: 1920,
        height: 1080,
        'aspect-ratio': '16:9',
    }
}

// An array of objects
[
    { name: 'Joe', age: 27 },
    { name: 'Jane', age: 32 },
]

4Arrays 4 数组

An array structure is represented as square brackets surrounding zero or more values (or elements). Elements are separated by commas. A single comma may follow the final element.数组结构用方括号表示,括号内包含零个或多个值(或元素)。元素之间用逗号分隔。最后一个元素后面可以跟一个逗号。

JSON5Array: JSON5 数组:[][JSON5ElementList,opt] [ JSON5 元素列表, 可选 ]JSON5ElementList: JSON5 元素列表:JSON5Value JSON5 值JSON5ElementList,JSON5ValueJSON5 元素列表,JSON5 值There is no requirement that the values in an array be of the same type.数组中的值没有要求必须是同一类型。

Example (Informative) 示例(信息性)

代码语言:javascript代码运行次数:0运行复制
// An empty array
[]

// An array with three elements
// and a trailing comma
[
    1,
    true,
    'three',
]

// Arrays can be nested
[
    [1, true, 'three'],
    [4, "five", 0x6],
]

5Strings 5 字符串

A string begins and ends with single or double quotation marks. The same quotation mark that begins a string must also end the string. All Unicode characters may be placed within the quotation marks, except for the characters that must be escaped: the quotation mark used to begin and end the string, reverse solidus, and line terminators.字符串以单引号或双引号开始和结束。开始字符串的相同引号也必须结束字符串。所有 Unicode 字符都可以放在引号内,除了必须转义的字符:用于开始和结束字符串的引号、反斜杠和换行符。

JSON5String:: JSON5 字符串::“JSON5DoubleStringCharactersopt”" JSON5 双引号字符串字符可选"‘JSON5SingleStringCharactersopt’'JSON5 单引号字符串字符 opt’JSON5DoubleStringCharacters::'JSON5 双引号字符串字符::'JSON5DoubleStringCharacterJSON5DoubleStringCharactersopt’JSON5 双引号字符串字符 JSON5 双引号字符串字符 opt’JSON5SingleStringCharacters::'JSON5 单引号字符串字符::'JSON5SingleStringCharacterJSON5SingleStringCharactersoptJSON5 单个字符串字符 JSON5 单个字符串字符可选JSON5DoubleStringCharacter::JSON5 双引号字符串字符::SourceCharacterbut not one of " or \ or LineTerminator源字符但不是 " 或 \ 或 行终止符\EscapeSequence 转义序列LineContinuation 行续行符U+2028U+2029JSON5SingleStringCharacter::JSON5 单字符串字符::SourceCharacterbut not one of ’ or \ or LineTerminator源字符,但不是 ’ 或 \ 或 行终止符之一\EscapeSequence 转义序列LineContinuation 行续行符U+2028U+2029# 5.1Escapes 5.1 转义

Any character may be escaped. If the character is in the Basic Latin or Latin-1 Supplement Unicode character ranges (U+0000 through U+00FF), then it may be represented as a four-character sequence: a reverse solidus, followed by the lower case letter x, followed by two hexadecimal digits that encode the character’s code point. A reverse solidus followed by the lower case letter x must be followed by two hexadecimal digits.任何字符都可以进行转义。如果字符在基本拉丁或拉丁-1 补充 Unicode 字符范围内(U+0000 至 U+00FF),则可以表示为四个字符的序列:一个反斜杠,后跟小写字母 x ,然后是两个表示字符代码点的十六进制数字。一个反斜杠后跟小写字母 x 必须后跟两个十六进制数字。

If the character is in the Basic Multilingual Plane (U+0000 through U+FFFF), then it may be represented as a six-character sequence: a reverse solidus, followed by the lower case letter u, followed by four hexadecimal digits that encode the character’s code point. A reverse solidus followed by the lower case letter u must be followed by four hexadecimal digits. The hexadecimal letters A though F can be upper or lower case.如果字符位于基本多语言平面(U+0000 至 U+FFFF),则它可以表示为一个六字符序列:一个反斜杠,后跟小写字母 u ,然后是四个十六进制数字,这些数字编码了字符的代码点。一个反斜杠后跟小写字母 u 必须后跟四个十六进制数字。十六进制字母 A 到 F 可以是大写或小写。

Example 1 (Informative) 示例 1(信息性)

A string containing only a single reverse solidus character may be represented as '\x5C' or '\u005C'.仅包含单个反斜杠字符的字符串可以表示为 ‘\x5C’ 或 ‘\u005C’ 。

To escape an extended character that is not in the Basic Multilingual Plane, the character is represented as a 12-character sequence, encoding the UTF-16 surrogate pair.要转义不在基本多语言平面的扩展字符,该字符表示为一个 12 字符序列,编码 UTF-16 代理对。

Example 2 (Informative) 示例 2(信息性)

A string containing only the musical score character

JSON5 格式标准 Data Exchange Format 官方文档 中英双语

Standard JSON5 标准 JSON5

1.0.0 / March 2018 1.0.0 / 三月 2018

The JSON5 Data Interchange FormatThe JSON5 数据交换格式

Abstract 摘要

The JSON5 Data Interchange Format is a proposed extension to JSON that aims to make it easier for humans to write and maintain by hand. It does this by adding some minimal syntax features directly from ECMAScript 5.1.JSON5 数据交换格式是一个提议的 JSON 扩展,旨在通过直接添加一些来自 ECMAScript 5.1 的最小语法特性,使人类更容易手动编写和维护。

1Introduction 1 介绍

The JSON5 Data Interchange Format (JSON5) is a superset of JSON that aims to alleviate some of the limitations of JSON by expanding its syntax to include some productions from ECMAScript 5.1.JSON5 数据交换格式(JSON5)是 JSON 的超集,旨在通过扩展其语法以包括一些来自 ECMAScript 5.1 的生产来缓解 JSON 的一些限制。

Similar to JSON, JSON5 can represent four primitive types (strings, numbers, Booleans, and null) and two structured types (objects and arrays).与 JSON 类似,JSON5 可以表示四种原始类型(字符串、数字、布尔值和 null)以及两种结构化类型(对象和数组)。

A string is a sequence of zero or more Unicode characters. Note that this citation references the latest version of Unicode rather than a specific release. It is not expected that future changes in the Unicode specification will impact the syntax of JSON5.字符串是由零个或多个 Unicode 字符组成的序列。请注意,此引用引用的是 Unicode 的最新版本,而不是特定版本。预计 Unicode 规范的未来变化不会影响 JSON5 的语法。

An object is an unordered collection of zero or more name/value pairs, where a name is a string or identifier and a value is a string, number, Boolean, null, object, or array.对象是一个无序集合,包含零个或多个键值对,其中键是一个字符串或标识符,值是字符串、数字、布尔值、null、对象或数组。

An array is an ordered sequence of zero or more values.数组是一个有序的值序列。

1.1Summary of Features 1.1 功能概述

The following ECMAScript 5.1 features, which are not supported in JSON, have been extended to JSON5.以下 ECMAScript 5.1 特性,这些特性在 JSON 中不受支持,已经被扩展到 JSON5 中。

Objects 对象

  • Object keys may be an ECMAScript 5.1 IdentifierName.对象的键可以是 ECMAScript 5.1 的标识符名称。
  • Objects may have a single trailing comma.对象可以有单个尾随逗号。

Arrays 数组

  • Arrays may have a single trailing comma.数组可以有单个尾随逗号。

Strings 字符串

  • Strings may be single quoted.字符串可以使用单引号。
  • Strings may span multiple lines by escaping new line characters.字符串可以通过转义换行符跨越多行。
  • Strings may include character escapes.字符串可以包含字符转义。

Numbers 数字

  • Numbers may be hexadecimal.数字可以是十六进制。
  • Numbers may have a leading or trailing decimal point.数字可以有一个前导或尾随的小数点。
  • Numbers may be IEEE 754 positive infinity, negative infinity, and NaN.数字可以是 IEEE 754 的正无穷、负无穷和 NaN。
  • Numbers may begin with an explicit plus sign.数字可以以显式的加号开头。

Comments 评论

  • Single and multi-line comments are allowed.允许单行和多行注释。

White Space 空白字符

  • Additional white space characters are allowed.允许额外的空白字符。

1.2Short Example 1.2 简例

Example (Informative) 示例(信息性)

代码语言:javascript代码运行次数:0运行复制
{
  // comments
  unquoted: 'and you can quote me on that',
  singleQuotes: 'I can use "double quotes" here',
  lineBreaks: "Look, Mom! \
No \\n's!",
  hexadecimal: 0xdecaf,
  leadingDecimalPoint: .8675309, andTrailing: 8675309.,
  positiveSign: +1,
  trailingComma: 'in objects', andIn: ['arrays',],
  "backwardsCompatible": "with JSON",
}

2Values 2 值

A JSON5 value must be an object, array, string, or number, or one of the three literal names true, false, or null.JSON5 值必须是一个对象、数组、字符串、数字,或者是三个字面量名称之一: true 、 false 或 null 。

JSON5Value: JSON5 值:JSON5Null JSON5 空值JSON5Boolean JSON5 布尔值JSON5String JSON5 字符串JSON5Number JSON5 数字JSON5Object JSON5 对象JSON5Array JSON5 数组# 3Objects 3 个对象

An object structure is represented as a pair of curly brackets surrounding zero or more name/value pairs (or members). A name is a string or identifier. A single colon comes after each name, separating the name from the value. A single comma separates a value from a following name. A single comma may follow the name/value pair. The names within an object should be unique.对象结构用一对花括号表示,其中包含零个或多个名称/值对(或成员)。名称是一个字符串或标识符。每个名称之后跟一个单冒号,将名称与值分开。一个值之后跟一个单逗号,与后面的名称分开。名称/值对之后可以跟一个单逗号。对象内的名称应该是唯一的。

JSON5Object: JSON5 对象:{}{JSON5MemberList,opt} { JSON5 成员列表, 选择}JSON5MemberList: JSON5 成员列表:JSON5Member JSON5 成员JSON5MemberList,JSON5MemberJSON5 成员列表, JSON5 成员JSON5Member: JSON5 成员:JSON5MemberName:JSON5ValueJSON5 成员名称: JSON5 值JSON5MemberName: JSON5 成员名称:JSON5Identifier JSON5 标识符JSON5String JSON5 字符串An object whose names are all unique is interoperable in the sense that all software implementations receiving that object will agree on the name-value mappings. When the names within an object are not unique, the behavior of software that receives such an object is unpredictable. Implementations may report the last name/value pair only, report an error or fail to parse the object, or report all of the name/value pairs, including duplicates.一个名称全部唯一的对象在互操作性方面是可行的,即所有接收该对象的软件实现都将同意名称-值映射。当对象内的名称不唯一时,接收此类对象的软件的行为是不可预测的。实现可能只报告最后一个名称/值对,报告错误或无法解析对象,或者报告所有名称/值对,包括重复项。

Implementations may make the ordering of object members visible to calling software. Implementations whose behavior does not depend on member ordering will be interoperable in the sense that they will not be affected by this.实现可能将对象成员的顺序对调用软件可见。那些行为不依赖于成员顺序的实现将在互操作性方面是可行的,即它们将不会受到影响。

Example (Informative) 示例(信息性)

代码语言:javascript代码运行次数:0运行复制
// An empty object
{}

// An object with two properties
// and a trailing comma
{
    width: 1920,
    height: 1080,
}

// Objects can be nested
{
    image: {
        width: 1920,
        height: 1080,
        'aspect-ratio': '16:9',
    }
}

// An array of objects
[
    { name: 'Joe', age: 27 },
    { name: 'Jane', age: 32 },
]

4Arrays 4 数组

An array structure is represented as square brackets surrounding zero or more values (or elements). Elements are separated by commas. A single comma may follow the final element.数组结构用方括号表示,括号内包含零个或多个值(或元素)。元素之间用逗号分隔。最后一个元素后面可以跟一个逗号。

JSON5Array: JSON5 数组:[][JSON5ElementList,opt] [ JSON5 元素列表, 可选 ]JSON5ElementList: JSON5 元素列表:JSON5Value JSON5 值JSON5ElementList,JSON5ValueJSON5 元素列表,JSON5 值There is no requirement that the values in an array be of the same type.数组中的值没有要求必须是同一类型。

Example (Informative) 示例(信息性)

代码语言:javascript代码运行次数:0运行复制
// An empty array
[]

// An array with three elements
// and a trailing comma
[
    1,
    true,
    'three',
]

// Arrays can be nested
[
    [1, true, 'three'],
    [4, "five", 0x6],
]

5Strings 5 字符串

A string begins and ends with single or double quotation marks. The same quotation mark that begins a string must also end the string. All Unicode characters may be placed within the quotation marks, except for the characters that must be escaped: the quotation mark used to begin and end the string, reverse solidus, and line terminators.字符串以单引号或双引号开始和结束。开始字符串的相同引号也必须结束字符串。所有 Unicode 字符都可以放在引号内,除了必须转义的字符:用于开始和结束字符串的引号、反斜杠和换行符。

JSON5String:: JSON5 字符串::“JSON5DoubleStringCharactersopt”" JSON5 双引号字符串字符可选"‘JSON5SingleStringCharactersopt’'JSON5 单引号字符串字符 opt’JSON5DoubleStringCharacters::'JSON5 双引号字符串字符::'JSON5DoubleStringCharacterJSON5DoubleStringCharactersopt’JSON5 双引号字符串字符 JSON5 双引号字符串字符 opt’JSON5SingleStringCharacters::'JSON5 单引号字符串字符::'JSON5SingleStringCharacterJSON5SingleStringCharactersoptJSON5 单个字符串字符 JSON5 单个字符串字符可选JSON5DoubleStringCharacter::JSON5 双引号字符串字符::SourceCharacterbut not one of " or \ or LineTerminator源字符但不是 " 或 \ 或 行终止符\EscapeSequence 转义序列LineContinuation 行续行符U+2028U+2029JSON5SingleStringCharacter::JSON5 单字符串字符::SourceCharacterbut not one of ’ or \ or LineTerminator源字符,但不是 ’ 或 \ 或 行终止符之一\EscapeSequence 转义序列LineContinuation 行续行符U+2028U+2029# 5.1Escapes 5.1 转义

Any character may be escaped. If the character is in the Basic Latin or Latin-1 Supplement Unicode character ranges (U+0000 through U+00FF), then it may be represented as a four-character sequence: a reverse solidus, followed by the lower case letter x, followed by two hexadecimal digits that encode the character’s code point. A reverse solidus followed by the lower case letter x must be followed by two hexadecimal digits.任何字符都可以进行转义。如果字符在基本拉丁或拉丁-1 补充 Unicode 字符范围内(U+0000 至 U+00FF),则可以表示为四个字符的序列:一个反斜杠,后跟小写字母 x ,然后是两个表示字符代码点的十六进制数字。一个反斜杠后跟小写字母 x 必须后跟两个十六进制数字。

If the character is in the Basic Multilingual Plane (U+0000 through U+FFFF), then it may be represented as a six-character sequence: a reverse solidus, followed by the lower case letter u, followed by four hexadecimal digits that encode the character’s code point. A reverse solidus followed by the lower case letter u must be followed by four hexadecimal digits. The hexadecimal letters A though F can be upper or lower case.如果字符位于基本多语言平面(U+0000 至 U+FFFF),则它可以表示为一个六字符序列:一个反斜杠,后跟小写字母 u ,然后是四个十六进制数字,这些数字编码了字符的代码点。一个反斜杠后跟小写字母 u 必须后跟四个十六进制数字。十六进制字母 A 到 F 可以是大写或小写。

Example 1 (Informative) 示例 1(信息性)

A string containing only a single reverse solidus character may be represented as '\x5C' or '\u005C'.仅包含单个反斜杠字符的字符串可以表示为 ‘\x5C’ 或 ‘\u005C’ 。

To escape an extended character that is not in the Basic Multilingual Plane, the character is represented as a 12-character sequence, encoding the UTF-16 surrogate pair.要转义不在基本多语言平面的扩展字符,该字符表示为一个 12 字符序列,编码 UTF-16 代理对。

Example 2 (Informative) 示例 2(信息性)

A string containing only the musical score character

本文标签: JSON5 格式标准 Data Exchange Format 官方文档 中英双语