YYsuni / react18-json-view

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

Editable non-object JSON roots #36

Closed marcklingen closed 2 months ago

marcklingen commented 4 months ago

Currently editable works if the root node is of type object. JSON roots can also be arrays or scalars, these do not seem to be editable in react18-json-view as of now (if I did not do a mistake).

Do you think adding this functionality is reasonable? Otherwise, we would build alternative UI in our project to toggle the JSON editor or default to a regular input field to edit scalars (strings).

Example (https://github.com/langfuse/langfuse) CleanShot 2024-02-26 at 16 28 57

YYsuni commented 4 months ago

OK, I will, my heavy account 😂.

YYsuni commented 4 months ago

react18-json-view@0.2.8-canary.2 available, Sir. @marcklingen

marcklingen commented 4 months ago

Thank you! Just tried it, does not work for me (no content is shown anymore). I upgraded from react18-json-view@0.2.8-canary.1 to react18-json-view@0.2.8-canary.2.

CleanShot 2024-02-29 at 12 04 53@2x

Implementation https://github.com/langfuse/langfuse/blob/2f55acec7c06116ea92a19764416c9ff388e3112/web/src/features/datasets/components/EditDatasetItem.tsx#L118-L130

YYsuni commented 4 months ago

Please try @0.2.8-canary.3 again. @marcklingen

marcklingen commented 4 months ago

Awesome! works on our end to edit strings that were already strings before.

Only question that's kind of left is how to switch from object to array to scalar when using the component to edit the object.

https://github.com/YYsuni/react18-json-view/assets/2834609/13545d31-f7af-452d-b1b5-bb001c90e42c

YYsuni commented 4 months ago

For creating a object, you can view https://github.com/YYsuni/react18-json-view?tab=readme-ov-file#editable. And others, I will take care of that.

YYsuni commented 4 months ago

On @0.2.8-canary.4, you could delete the root node and reset it, @marcklingen

YYsuni commented 4 months ago

@marcklingen Hi?

marcklingen commented 2 months ago

Hi @YYsuni, I tried it again a couple of times but then got a lot of feedback by our users who edit a lot of JSON within our application. We switched to codemirror for editing and use react18-json-viewer for viewing of JSON across the UI. react18-json-viewer is awesome when editing single values but not when writing large JSON objects. Having multi-cursors and other editor features is preferred for that use case.