Understand incremental value updates and invariants
mainAs JSON streams in, jsonriver yields a sequence of values that grow in completeness. To ensure predictable behavior, the parser follows these invariants:
- Type Stability: Subsequent versions of a value will have the same type (except when an object has repeated keys).
- Atomicity:
true,false,null, and numbers are yielded only when the entire value is available. - String Growth: Strings are updated by appending more characters.
- Array Updates: Arrays are modified by appending new elements or mutating the element currently at the end.
- Object Updates: Objects are modified by adding new properties or mutating the most recently added property.
- Property Addition: A property is only added to an object once the full key and the value's type are known.
- Repeated Keys: If an object contains the same key multiple times, later values take precedence, matching
JSON.parsebehavior. This is the only case where a value's type might change or earlier keys might be removed.