a: 1, b: 2
Forgiving Features
zzson
is a forgiving JSON parser, handling common deviations from strict JSON (RFC 8259). Below are the supported forgiving features:
Comments
- Single-line:
// ...
and# ...
- Multi-line:
/* ... */
Comments are ignored anywhere whitespace is allowed.
Example:
{
// This is a single-line comment
age: 30, # Another single-line comment
/* Multi-line
comment */
name: "Alice"
}
Unquoted Keys
Object keys can be unquoted if they are valid identifiers.
{ name: "zzson", version: 1.0 }
Trailing Commas
Trailing commas are allowed in arrays and objects.
{
a: 1,
b: 2,
}
Implicit Top-Level Objects and Arrays
You can omit brackets for top-level arrays or objects:
apple, banana, cherry
# Interpreted as ["apple", "banana", "cherry"]
# Interpreted as {"a": 1, "b": 2}
Newlines as Comma Separators
When enabled, newlines can act as value separators, like commas, in arrays and objects.
[
1
2
3
]
{
key1: "value1"
key2: "value2"
}
Extended Number Formats
- Hexadecimal:
0xFF
- Octal:
0o77
- Binary:
0b1010
- Underscores:
1_000_000
Single-Quoted Strings
Both single and double quotes are supported for strings.
{ key: 'value', other: "also ok" }
Strict Mode
All forgiving features can be disabled for strict RFC 8259 compliance.
These forgiving features make zzson
a flexible parser for configurations, data files, and other scenarios where strict JSON adherence might be relaxed.