Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing JSON schema to detect objects with duplicate names

According to the following post;

Does JSON syntax allow duplicate keys in an object?

Keys with the same name in JSON are valid, but most parsers will override the value with the last value it finds. Is there anyway in a json schema to detect duplicate names and throw an error? I want all json keys to have unique names in an object.

like image 244
Mike Mellor Avatar asked Sep 30 '22 16:09

Mike Mellor


1 Answers

Json-schema works with valid JSON objects, so there is nothing it can do to prevent duplicate keys.

I would suggest you to use a jsonlint as a preprocess before validating with json-schema validator. It will depend on your programming language but here you have some choices:

  • javascript.
  • PHP
  • Python
like image 164
jruizaranguren Avatar answered Oct 03 '22 23:10

jruizaranguren