Grep duplicate JSON keys

If you have large JSON files with application settings in, you need to be sure that the settings only appear once. Not a problem until you get to the stage of very large files, being edited by all sorts of people manually.

[
"setting_1" : "some value",
"setting_2" : "another value",
"setting_1" : "different again"
]

Run a script to check for duplicate key names:

grep -Po '"[a-z_0-9]+"[ ]*:' <filename> | uniq -d

The above will output the duplicated setting(s) if any, to the console. Tested on Ubuntu 12.04

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>