Zum Inhalt springen
uencoder

JSON5-Spezifikation

JSON5 ist ein superset von JSON enabling comments, trailing commas, unquoted Schlüssel, und mehr relaxed syntax.

Syntax Extensions

JSON5 allows single and multi-line comments using // and /* */ syntax. Object keys may be unquoted if they are valid identifiers. Strings can use single quotes in addition to double quotes. Trailing commas in arrays and objects are permitted. Numbers support hexadecimal notation, leading/trailing decimal points, and positive/negative infinity.

comments
Single and multi-line
// line /* block */
unquoted keys
Valid identifiers
{ key: 1 }
hex numbers
Hexadecimal notation
0xFF

Compatibility and Parsing

Every valid JSON document is also valid JSON5, ensuring backward compatibility. JSON5 parsers are available for JavaScript, Python, and other languages. The format is primarily intended for human-edited configuration files, not data interchange. JSON5 is not an official standard but is widely adopted in tooling. For machine-to-machine exchange, standard JSON remains preferred.

superset
Valid JSON is valid JSON5
backward compatible
use case
Config files, not interchange
human-edited
parsers
Available in many languages
npm: json5

Verwandte Tools

参考链接