Flatten JSON safely: JSON Pointer, empty containers and large integers
See why dotted paths lose meaning and how a containers/values envelope preserves arrays, objects and large numeric tokens during flattening.
Dotted paths are not unique
The objects {"a.b":1} and {"a":{"b":1}} should not collapse into the same a.b path. Keys can also contain slashes, tildes or an empty string.
JSON Pointer defines escapes for slash and tilde characters. Standard paths reduce ambiguity, but paths alone cannot represent every container detail.
Restoring paths is now part of Flatten and restore JSON; key sorting lives under Task in the JSON formatting workspace.
Empty containers need a place to live
An empty array has no leaf value, so a leaf-only transformation may discard it. An object key named "0" must not silently become an array index.
Neatbo outputs separate containers and values maps. Reconstruction creates arrays and objects before placing values, preserving empty structures.
Protect numbers when reading them
A large integer converted to floating point may already have lost digits before formatting begins. Record identifiers are a common place for this mistake to matter.
These transformations preserve number tokens and reject duplicate keys within an object. Still check the receiving system: its JSON parser may use a different numeric representation.
Build an awkward example before trusting a round trip
The example combines a literal dotted key, a nested object, a slash-containing key, an empty array and an object whose key is “0”. These cases look similar in a simple flattened spreadsheet but have different JSON structures.
JSON Pointer escapes ~ as ~0 and / as ~1 inside path segments. It does not give a dot special meaning. In this example /a.b addresses the literal key, while /a/b addresses the nested value. A leading slash introduces a segment; the empty pointer addresses the whole document.
Neatbo’s separate container map records whether a path represents an object or an array, including empty ones. That envelope is an application format, not a requirement of JSON Pointer itself. Use the matching unflatten tool and compare the reconstructed data before adopting the representation in another system.
| Value to locate | Pointer | Why it differs |
|---|---|---|
| Literal a.b | /a.b | Dot remains part of the key |
| Nested b | /a/b | Two path segments |
| Literal x/y | /x~1y | Slash is escaped |
| Object key 0 | /labels/0 | Container type must remain object |
{"a.b":1,"a":{"b":2},"x/y":3,"empty":[],"labels":{"0":"zero"},"id":9007199254740993}Before you finish
- Compare structure and values, not just pretty-printed text.
- Check empty arrays and objects after reconstruction.
- Preserve numeric tokens before a floating-point parser can round them.
- Reject ambiguous duplicate keys rather than guessing which value should survive.
References
- RFC 6901: JSON Pointer
Defines pointer paths and escaping, not Neatbo’s containers/values envelope.