YYsuni / react18-json-view

JSON viewer for react18
https://jv.yysuni.com/
MIT License
236 stars 15 forks source link

Add displayArrayKey Option for Rendering Array Keys in JSONViewer #19

Open Cylop opened 9 months ago

Cylop commented 9 months ago

Greetings,

I have implemented a new feature in the JSONViewer, introducing an option named displayArrayKey. This feature aims to enhance the user experience by providing additional flexibility in visualizing JSON data.

Feature: 'displayArrayKey' Option

The displayArrayKey option, when set to false, prevents the rendering of the keys of an array and appends a colon to the end of the line. This results in a cleaner and more concise output for users who find array keys unnecessary in certain contexts.

Usage:

<JsonView
  src={object}
  displayArrayKey={false}
/>

Enabled (without keys):

Bildschirmfoto 2023-09-27 um 23 39 28

Disabled (with keys):

Bildschirmfoto 2023-09-27 um 23 39 47

Use Case:

This addition is beneficial for developers seeking a streamlined representation of JSON data, especially when handling large arrays where the keys might not contribute significantly to comprehending the data structure.

Documentation:

The documentation has been updated to encompass the new displayArrayKey option, elucidating its function and effect on the JSON data representation.

Conclusion:

I am confident that this feature will serve as a valuable enhancement to the project by offering more versatility in displaying JSON data. I look forward to your feedback and am open to making any necessary modifications.

Thank you for considering this contribution. Looking forward to a positive review and eventual merge.

Best Regards, Nicholas

vercel[bot] commented 9 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
json-view ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 28, 2023 4:46am
react18-json-view ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 28, 2023 4:46am
YYsuni commented 9 months ago

I noticed the new comma added and had a thought: why do we add the prop viewMode: viewer or json? Which means json mode has the comma symbol, but the viewer mode not.

Cylop commented 9 months ago

That sounds like a good idea, I'll implement the comments!

Cylop commented 9 months ago

I started changing right now, do you think with the view mode 'viewer' or 'json' - do we need the displayArrayKey option at all?

Cylop commented 9 months ago

I introduced now the new option viewMode with options['json', 'viewer'] where 'viewer' is the default one. Once 'json' is selected, commas are appended to the end of the line, whereas 'displayArrayKey' only the display of array keys disabled.

I removed the package-lock and used pnpm (missed that before)

I also removed the new file and adapted the existing 'name-value.tsx'.

This options are now available:

Bildschirmfoto 2023-09-28 um 06 53 21 Bildschirmfoto 2023-09-28 um 06 53 09 Bildschirmfoto 2023-09-28 um 06 52 34 Bildschirmfoto 2023-09-28 um 06 52 51
YYsuni commented 9 months ago

Sorry, I am on vacation.