Introduction
JSON (JavaScript Object Notation) has established itself as the de facto standard for data exchange across the web. However, as data volumes grow, traditional validation methods—which typically involve parsing an entire document into a Document Object Model (DOM) before checking it against a schema—encounter significant scalability issues. For massive JSON files, the memory overhead of DOM-based validation can lead to system crashes.
This research presents a streaming validation approach that processes JSON documents symbol-by-symbol. By representing schemas as Visibly Pushdown Automata (VPA) and employing active learning, the authors provide a memory-efficient solution capable of handling complex, nested structures without loading the full document into RAM.
The Challenge: Unordered Keys in a Streaming Context
The primary hurdle for streaming JSON validation is the "unordered key" property of JSON objects. While arrays require elements to appear in a specific sequence, the key-value pairs within an object can appear in any order. Standard finite-state machines or pushdown automata typically expect a fixed sequence of input symbols. Reconciling this flexibility with the rigid requirements of formal automata is the core technical challenge addressed in this work.
Methodology
The researchers propose a multi-faceted approach combining formal language theory with machine learning:
1. Visibly Pushdown Automata (VPA)
The authors demonstrate that JSON schemas can be formally represented as VPAs. Unlike standard pushdown automata, VPAs distinguish between "call" symbols (opening braces or brackets) and "return" symbols (closing braces or brackets). This distinction allows the automaton to manage a stack efficiently, making it ideal for the nested, hierarchical nature of JSON.
2. Active Learning via the TTT Algorithm
Manually constructing a VPA for every possible JSON schema is impractical. Instead, the researchers use active learning—specifically the TTT algorithm—to automatically build the automaton. The learner interacts with a "teacher" (a classical validator) by posing queries about whether specific JSON fragments are valid. Over time, the learner converges on a complete VPA that accurately reflects the schema's constraints.
3. The Key Graph
To handle unordered keys, the authors introduce the "key graph." While the learned VPA might assume a specific internal order (e.g., alphabetical), the key graph abstracts these transitions. It allows the streaming validator to track all valid permutations of keys as they arrive in the stream, ensuring that the validator remains order-agnostic for objects while maintaining order-sensitivity for arrays.
Evaluation and Results
The approach was tested against six JSON schemas of varying complexity, ranging from simple recursive lists to industrial-grade configurations like Azure Functions Proxies and Codecov.
- Memory Efficiency: The streaming validator demonstrated superior memory performance compared to classical recursive validators. While traditional methods scale memory usage with document size, the streaming approach's footprint is primarily determined by schema complexity and nesting depth, making it far more stable for large-scale data.
- Performance Trade-offs: The transition to streaming involves a time-memory trade-off. The streaming algorithm requires more CPU cycles to maintain sets of valid states and traverse the key graph. However, this overhead is often acceptable in scenarios where memory is the primary bottleneck.
- Scalability: The system successfully learned most schemas, though extremely complex ones like
codecovhighlighted the limits of current active learning speeds, resulting in partially learned but functional models.
Conclusion
By bridging the gap between formal automata and the practical realities of JSON data, this research offers a robust framework for high-performance data validation. The combination of VPAs, active learning, and key graphs provides a path forward for processing the massive, nested data streams that define the modern web. Future work aims to integrate more granular value checks and optimize the learning phase for even larger industrial schemas.
Summary updated