josdejong / svelte-jsoneditor

A web-based tool to view, edit, format, repair, query, transform, and validate JSON
https://jsoneditoronline.org
Other
897 stars 108 forks source link

Automatically repair pasted contents in text mode like in tree mode #177

Open mariusa opened 1 year ago

mariusa commented 1 year ago

At https://www.freeformatter.com/json-formatter.html#before-output I can paste this

{ age: 22 }

and it will format to add quotes for attributes, eg "age"

Please allow the same for https://jsoneditoronline.org/

josdejong commented 1 year ago

Hi Marius, thanks for your input. https://jsoneditoronline.org/ already has auto repair capability:

After pasting in text mode:

afbeelding

After pasting in tree mode:

afbeelding

Is that what you mean?

mariusa commented 1 year ago

Hi Jos, thanks. I see, so one has to paste with Tree mode, not with Text mode, which isn't intuitive. Would it be possible to auto-repair after pasting within Text mode too?

josdejong commented 1 year ago

so one has to paste with Tree mode, not with Text mode, which isn't intuitive.

Not really, all you have to do in text mode is click the big red "Auto repair" button bottom right.

What I find important is that the editor not "automagically" makes changes in content, but that you as a user are in control. It is an interesting idea though to automatically repair contents in text mode too, like in tree mode, as long as there is this clear message at the bottom allowing you to revert the changes and do it yourself. Let me think about it.

mariusa commented 1 year ago

click the big red "Auto repair" button bottom right.

Ah, I really missed that! That works, thanks! Feel free to handle as you wish then, or close the issue

josdejong commented 1 year ago

Well, I really like your idea. I think normally you paste JSON to do something with it and get it fixed. So if you paste invalid JSON, you will normally always click the "Auto repair" button right after that. So it makes sense to me to automatically "click" the button for you and show a button to undo the repair action instead for the edge cases.

So let me keep this issue open and change the title according to this plan.

mariusa commented 1 year ago

Perfect! Thanks for being open to feedback :)

drik98 commented 10 months ago

Hey @josdejong I would really appreciate this feature. I currently have the problem that the pasted json content is not recognized as unformatted. I guess because it is not "compact" enough. If it was auto formatted anyway that would resolve this issue.

josdejong commented 10 months ago

@drik98 this issue is about auto repair, which is different from auto format. I think it should be configurable, and I can imagine something like an "auto format on save" feature too (not part of the editor but maybe of https://jsoneditoronline.org).