When you need a stack
The previous lesson ended at a ceiling: finite automata cannot count without bound, so genuinely recursive formats are out of reach.
The next class up is the context-free languages, recognised by a pushdown automaton. A pushdown automaton is a finite automaton with one addition: a stack it can push to and pop from.
That single addition is enough. To validate nesting, push a marker on every opening brace and pop on every closing one. A closing brace is legal exactly when the stack is non-empty and its top matches. At the end, the input is complete exactly when the stack is empty.
Context-free grammars are the notation for describing these languages, written as production rules: a value is an object or an array or a string or a number; an object is a brace, then members, then a brace. The rules may refer to themselves, which is precisely what regular expressions cannot do.
This covers what people actually want to constrain: arbitrary JSON, SQL dialects, programming languages, arithmetic expressions, and any domain-specific format with nested structure.

