json-viewer icon indicating copy to clipboard operation
json-viewer copied to clipboard

Feat : collapse the JSON by default

Open tamilarasan-n-dev opened this issue 11 months ago • 1 comments

Hi,

First of all, thanks for creating this awesome JSON viewer! I'm using it in my project and it works great. However, I noticed that there is no built-in option to collapse all JSON nodes by default.

It would be really helpful if you could add a collapsed: true (or similar) option so that the JSON viewer initializes with all nodes collapsed. This would improve usability, especially when dealing with large JSON objects.

Proposed Feature:

Add a collapsed option (default: false). When set to true, all nodes should be collapsed on initialization. Optionally, allow setting a collapse level (e.g., collapsed: 1 to collapse only the first level). Current Workaround: Right now, I'm manually selecting all .json-toggle elements and triggering a click event after rendering, but having this as a built-in feature would be much more efficient.

Would love to hear your thoughts on this! Thanks again for your work.

Best, Tamilarasan

tamilarasan-n-dev avatar Feb 12 '25 14:02 tamilarasan-n-dev

You can already do this by setting defaultInspectDepth={1}. Change the value to fit your needs.

pionxzh avatar Feb 15 '25 17:02 pionxzh