Duplicate key error does not fire a validation error
Hello, It would be nice to have a validation error when the input contains a duplicate key.
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.
+1
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.
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?
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.
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
agree