Thursday, November 9, 2017

verify JSON files in the shell (npm, bash)

I do most of my mass text-processing in Perl. It's been a wake-up that Perl's JSON libraries & tools are a little eccentric (perhaps that shouldn't be surprising) or 'minimal', rather than warm & fuzzy: that would be the best word.

Anyway. Let's verify a bunch of json files in the shell. This follows a lengthy period of combining &  de-duplicating two (pretty crap & overlapping) datasets into a single json format. 

Install jsonlint from via npm: https://www.npmjs.com/package/jsonlint

This gives you a decent executable json linter which may or may not be the same codebase as the ever-awesome http://jsonlint.com/

and call it from the shell:

for f in *.json 
do 
 echo "Processing $f" 
 jsonlint -cq $f 
done

the q flag prevents json printing to the shell & only shows errors

No comments: