jsoneditor icon indicating copy to clipboard operation
jsoneditor copied to clipboard

Duplicate key error does not fire a validation error

Open klitim opened this issue 5 years ago • 7 comments

Hello, It would be nice to have a validation error when the input contains a duplicate key.

klitim avatar Jun 18 '20 14:06 klitim

That is an interesting idea. It is very hard to achieve though, and I think it's not worth the effort at this point.

The issue is that duplicate keys are only possible in serialized text containing JSON. As soon as you parse JSON, there are no duplicates anymore. So this would mean we would have to write a custom JSON parser which can detect duplicates. I think this is a bit out of scope.

josdejong avatar Jun 20 '20 12:06 josdejong

+1

blacksunset avatar Oct 27 '20 07:10 blacksunset

Hi. I have to implement a nice features using this editor and stuck with this duplication error too. You already have "Duplicate key" error shown on ruler. I have done my own external solution, but it is far from the best. Maybe you can add this error to be thrown with the onValidationError? This can be an option.

Screenshot 2020-11-12 at 23 59 54

UPD: Ok, i realised, that this is more related to Ace editor. But anyway, maybe there is event that Ace editor fires up, and this can be also passed through?

ComradeLV avatar Nov 12 '20 22:11 ComradeLV

Ahh, that is an interesting idea. In code mode it should indeed be possible to capture this "Duplicate key" error from Ace editor, and pass it through via onValidationError. It would not work though in tree and text mode, so in that sense it would be inconsistent.

Maybe we can find a little JSON validator library which can recognize such issues, or we can figure out how Ace editor does generate those errors. It would be nice to have a solution which works consistently in all modes.

I recently published https://github.com/josdejong/simple-json-repair (used under the hood by JSONEditor), maybe we could extend this library to also report (and fix) duplicate key issues.

josdejong avatar Nov 13 '20 13:11 josdejong

I think the better way is to

figure out how Ace editor does generate those errors

Because otherwise you will make a duplicate of existing functionality - potential performance lack

ComradeLV avatar Nov 14 '20 18:11 ComradeLV

agree

josdejong avatar Nov 14 '20 18:11 josdejong