{
"version": "4.0",
"category": "encode",
"description": "Primitive value encoding – strings, numbers, booleans, null",
"tests": [
{
"name": "encodes safe strings without quotes",
"input": "hello",
"expected": "hello",
"specSection": "7.2"
},
{
"name": "encodes safe string with underscore and numbers",
"input": "Ada_99",
"expected": "Ada_99",
"specSection": "7.2"
},
{
"name": "quotes empty string",
"input": "",
"expected": "\"\"",
"specSection": "7.2"
},
{
"name": "quotes string that looks like true",
"input": "true",
"expected": "\"true\"",
"specSection": "7.2"
},
{
"name": "quotes string that looks like false",
"input": "false",
"expected": "\"false\"",
"specSection": "7.2"
},
{
"name": "quotes string that looks like null",
"input": "null",
"expected": "\"null\"",
"specSection": "7.2"
},
{
"name": "quotes string that looks like integer",
"input": "42",
"expected": "\"42\"",
"specSection": "7.2"
},
{
"name": "quotes string that looks like negative decimal",
"input": "-3.14",
"expected": "\"-3.14\"",
"specSection": "7.2"
},
{
"name": "quotes string that looks like scientific notation",
"input": "1e-6",
"expected": "\"1e-6\"",
"specSection": "7.2"
},
{
"name": "quotes string with leading zero",
"input": "05",
"expected": "\"05\"",
"specSection": "7.2",
"note": "Matches the numeric-like pattern, so it MUST be quoted"
},
{
"name": "escapes newline in string",
"input": "line1\nline2",
"expected": "\"line1\\nline2\"",
"specSection": "7.1"
},
{
"name": "escapes tab in string",
"input": "tab\there",
"expected": "\"tab\\there\"",
"specSection": "7.1"
},
{
"name": "escapes carriage return in string",
"input": "return\rcarriage",
"expected": "\"return\\rcarriage\"",
"specSection": "7.1"
},
{
"name": "encodes string with U+0004 control character via \\uXXXX",
"input": { "val": "a\u0004b" },
"expected": "val: \"a\\u0004b\"",
"specSection": "7.1"
},
{
"name": "escapes backslash in string",
"input": "C:\\Users\\path",
"expected": "\"C:\\\\Users\\\\path\"",
"specSection": "7.1"
},
{
"name": "quotes string with array-like syntax",
"input": "[3]: x,y",
"expected": "\"[3]: x,y\"",
"specSection": "7.2"
},
{
"name": "quotes string starting with hyphen-space",
"input": "- item",
"expected": "\"- item\"",
"specSection": "7.2"
},
{
"name": "quotes single hyphen as object value",
"input": { "marker": "-" },
"expected": "marker: \"-\"",
"specSection": "7.2",
"note": "Single hyphen must be quoted to avoid list item ambiguity"
},
{
"name": "quotes string starting with hyphen as object value",
"input": { "note": "- item" },
"expected": "note: \"- item\"",
"specSection": "7.2"
},
{
"name": "quotes single hyphen in array",
"input": { "items": ["-"] },
"expected": "items[1]: \"-\"",
"specSection": "7.2"
},
{
"name": "quotes leading-hyphen string in array",
"input": { "tags": ["a", "- item", "b"] },
"expected": "tags[3]: a,\"- item\",b",
"specSection": "7.2"
},
{
"name": "quotes string with bracket notation",
"input": "[test]",
"expected": "\"[test]\"",
"specSection": "7.2"
},
{
"name": "quotes string with brace notation",
"input": "{key}",
"expected": "\"{key}\"",
"specSection": "7.2"
},
{
"name": "encodes Unicode string without quotes",
"input": "café",
"expected": "café",
"specSection": "7.2"
},
{
"name": "encodes Chinese characters without quotes",
"input": "你好",
"expected": "你好",
"specSection": "7.2"
},
{
"name": "encodes emoji without quotes",
"input": "🚀",
"expected": "🚀",
"specSection": "7.2"
},
{
"name": "encodes string with emoji and spaces",
"input": "hello 👋 world",
"expected": "hello 👋 world",
"specSection": "7.2"
},
{
"name": "encodes emoji inside a quoted string",
"input": "a,🚀",
"expected": "\"a,🚀\"",
"specSection": "7.1",
"note": "Quoting is triggered by the delimiter; the supplementary scalar stays literal UTF-8, never a surrogate escape"
},
{
"name": "encodes positive integer",
"input": 42,
"expected": "42",
"specSection": "2"
},
{
"name": "encodes decimal number",
"input": 3.14,
"expected": "3.14",
"specSection": "2"
},
{
"name": "encodes negative integer",
"input": -7,
"expected": "-7",
"specSection": "2"
},
{
"name": "encodes zero",
"input": 0,
"expected": "0",
"specSection": "2"
},
{
"name": "encodes negative zero as zero",
"input": -0,
"expected": "0",
"specSection": "2"
},
{
"name": "encodes large integer without exponent notation",
"input": 1000000,
"expected": "1000000",
"specSection": "2",
"note": "Within the canonical decimal range"
},
{
"name": "encodes small decimal without exponent notation",
"input": 0.000001,
"expected": "0.000001",
"specSection": "2",
"note": "Lower bound of the canonical decimal range"
},
{
"name": "encodes large number",
"input": 100000000000000000000,
"expected": "100000000000000000000",
"specSection": "2"
},
{
"name": "encodes MAX_SAFE_INTEGER",
"input": 9007199254740991,
"expected": "9007199254740991",
"specSection": "2"
},
{
"name": "encodes repeating decimal with full precision",
"input": 0.3333333333333333,
"expected": "0.3333333333333333",
"specSection": "2"
},
{
"name": "encodes true",
"input": true,
"expected": "true",
"specSection": "2"
},
{
"name": "encodes false",
"input": false,
"expected": "false",
"specSection": "2"
},
{
"name": "encodes null",
"input": null,
"expected": "null",
"specSection": "2"
},
{
"name": "quotes leading-plus numeric-like string",
"input": "+1",
"expected": "\"+1\"",
"specSection": "7.2",
"note": "Unquoted, a v3 host-parser decoder would read the number 1"
},
{
"name": "quotes string equal to hash",
"input": "#",
"expected": "\"#\"",
"specSection": "7.2",
"note": "Comment marker at position 0 must be quoted"
},
{
"name": "quotes string starting with hash",
"input": "#hello",
"expected": "\"#hello\"",
"specSection": "7.2"
}
]
}