JSON.prune
JSON.prune copied to clipboard
Bring Objects to highest level in output
A complex structure can show the highest level item as 'pruned' forcing one to sift through the json atring to find the one unpruned source. Example: https://jsonblob.com/bf90de6d-caf5-11e7-8bfc-27c198b81400
In the example, the root level "server" is pruned and the original is somewhere in the json with a key NOT labeled "server" making it VERY difficult to find. It would be much better if the root level server had the object.
Am I right in saying that what you want is having, for every set of positions an object is referred to, to keep the one which is at the lowest depth ?
If so this is an interesting request.
Yeah. If by lowest you mean lowest index.
Current
_object: { server: { ... } }, server: "-pruned-"
Desired:
_object: { server: "-pruned-" }, server: { ... }
The request is clear.
The problem is that to do this I'd need to handle the object to stringify in two times : a BFS traversal to know where to keep and where to prune, followed by the DFS traversal which is the natural order of JSON writing.
This is feasible but not totally trivial to minimize the impact on performance.
As the changes envisioned here would take some time to code and wouldn't be without impact on the library size and efficiency, I'd like to have more feedback from users before diving into it.
Please comment here or on Miaou.
Could this be opt-in?
For the performance, yes. But not reasonably for the library size.