JSON.prune icon indicating copy to clipboard operation
JSON.prune copied to clipboard

Bring Objects to highest level in output

Open bholbrook73 opened this issue 7 years ago • 6 comments

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.

bholbrook73 avatar Nov 16 '17 17:11 bholbrook73

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.

Canop avatar Nov 16 '17 18:11 Canop

Yeah. If by lowest you mean lowest index.

Current _object: { server: { ... } }, server: "-pruned-"

Desired: _object: { server: "-pruned-" }, server: { ... }

bholbrook73 avatar Nov 16 '17 19:11 bholbrook73

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.

Canop avatar Nov 17 '17 06:11 Canop

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.

Canop avatar Nov 20 '17 17:11 Canop

Could this be opt-in?

ralt avatar Nov 20 '17 17:11 ralt

For the performance, yes. But not reasonably for the library size.

Canop avatar Nov 20 '17 17:11 Canop