DailyJS

Jsawk and JSONLint

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

JSON validation cli

Jsawk and JSONLint

Posted by Alex R. Young on .
Featured

JSON validation cli

Jsawk and JSONLint

Posted by Alex R. Young on .

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

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.