Fix invalid JSON files
Last updated:
You have bunch of improperly formatted JSON files and want an automated way to fix them.
Install hjson via
npm i -g hjsonLets assume we have the file:
// This file contains comments which are not allowed in JSON[ {id: 1, moo: true}, // missing quotes {"id": 2}, // invalid trailing commas]To fix just pipe it into hjson:
$ cat a.json | hjson -j[ { "id": 1, "moo": true }, { "id": 2 }]You can then pipe the result into other CLI tools such as fx for further analysis:
$ cat a.json | hjson -j | fx 'map("id")'[ 1, 2]