Jsawk and JSONLint

2010-03-23 00:00:00 +0000 by Alex R. Young

Jsawk is like awk for JSON. It can be used to filter JSON, or modify it. Each record can be
processed using JavaScript expressions.

Given this JSON:

    "id": "1",
    "name": "alex",
    "roles"  : ["author", "editor"]
    "id": "2",
    "name": "simon",
    "roles"  : ["author", "editor"]
    "id": "3",
    "name": "bill",
    "roles"  : ["author"]

An email field could be added like this:

cat example.json | ./jsawk 'this.email = this.name + "@dailyjs.com"'

This filters out all people who aren't an editor:

cat example.json | ./jsawk 'if (this.roles.indexOf("editor") == -1) return null'


JSONLint is a web-based tool for validating JSON. Paste in some JSON and it'll give you syntax errors. It's simple
but may be convenient if you're stuck on a JSON problem and don't have a
quick way to validate it.