josdejong / svelte-jsoneditor

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

Do not throw a duplicate key error when the duplicate values are equal #235

Closed wongshung closed 6 months ago

wongshung commented 1 year ago

When there is a duplicate key in json, now it could not automatically remove one key on clicking "Format JSON". In previous classic version of json editor, it is fine to do that. I think it should be a better feature to just automatically repair the duplicate key, especially when key and value are exactly the same.

josdejong commented 1 year ago

If you have a duplicate like {"name": "Joe", "name": "Sarah"}, the classic version of the JSON editor would always give you the last version, in this case "name": "Sarah". It would silently throw away the first. I think throwing away data is not a good default behavior, and duplicates should be solved by the user instead.

When there is a duplicate key but both hold the same value, there is not actually a conflict and we could solve that without trowing an error. That's a good idea, I'll implement that.

josdejong commented 6 months ago

Right now the editor shows the option to Auto Repair JSON with duplicate keys, so you can click "Auto Repair" followed by "Format" to get things done. I have the idea that this is not a common issue, so I'm in doubt whether it is worth spending efforts to improve on this. I'll close this issue now, but feel free to reopen if needed.

josdejong commented 6 months ago

O wait, this actually works already 😂 , at least with the lossless-json parser.