RFC 8259 Context-Free Grammar & Tree Depth Equations
Standard JSON parsing evaluates recursive context-free grammar rules to validate document syntax:
1. Formal JSON Grammatical Production Rule
JSON-Text = ws · (Object | Array) · ws, Value = Object | Array | String | Number | true | false | null
2. AST Structural Nesting Depth Formula
MaxDepth(N) = 1 + max_{c ∈ Children(N)} MaxDepth(c)
Step-by-Step Lexical Analysis & Recursive Descent Breakdown
Step 1: Character Stream Tokenization
Scan literals, string delimiters ("), braces ({}), and numeric values.
Step 2: Grammar State Transition Verification
Ensure keys have double quotes and trailing commas are omitted.
Step 3: Syntax Verification Verdict
Syntax Result=Valid RFC 8259 JSON
Common JSON Syntax Failures & Resolution Reference
| Syntax Error Type | Invalid Example | Valid Correction | Rule Violation |
|---|---|---|---|
| Trailing Comma | {"a": 1,} | {"a": 1} | No trailing comma allowed before closing brace |
| Single Quotes | {'name': 'Alex'} | {"name": "Alex"} | Keys and strings must use double quotes (") |
| Unquoted Keys | {id: 101} | {"id": 101} | Object properties must be string literals |
| Comments | // comment | {"_comment": "..."} | RFC 8259 forbids comments |