-
Notifications
You must be signed in to change notification settings - Fork 94
Description
Issue
The current specification for “literal arrays” leaves room for multiple interpretations. It is not defined whether arrays nested inside objects (or deeper structures) must be escaped, or if escaping applies only to top-level arrays. This ambiguity can lead to inconsistent behavior across implementations.
Recommendation
Update the specification to state that all arrays, regardless of context, must be escaped by wrapping them in an outer array.
Examples:
- [1,2,3] → [[1,2,3]]
- [] → [[]]
- {"items": [1,2]} → {"items": [[1,2]]}
- {"data": {"items": []}} → {"data": {"items": [[]]}}
This approach provides a single, unambiguous rule, aligns with the TypeScript reference implementation, and ensures consistent behavior across languages.
Context
While developing the Rust implementation (capn-rs), my initial serializer generated unescaped arrays inside objects. To test this approach, I patched the TypeScript reference implementation to accept them. Although workable, this added complexity and diverged from the reference behavior. After exploring both paths, I found that escaping arrays at all levels is simpler, consistent, and a better fit for interoperability.