Sample JSON File

Sample JSON File containing well known programmers that we use for the following examples

coders.json
[
  {
    "name": "Bjarne Stroustrup",
    "languages": [
      {
        "name": "C++",
        "year_created": 1983
      }
    ],
    "details": {
      "nationality": "Danish",
      "awards": ["IEEE Computer Society Computer Pioneer Award", "Charles Stark Draper Prize"]
    }
  },
  {
    "name": "Guido van Rossum",
    "languages": [
      {
        "name": "Python",
        "year_created": 1991
      }
    ],
    "details": {
      "nationality": "Dutch",
      "awards": ["Free Software Foundation Award for the Advancement of Free Software", "NLUUG Award"]
    }
  },
  {
    "name": "James Gosling",
    "languages": [
      {
        "name": "Java",
        "year_created": 1995
      }
    ],
    "details": {
      "nationality": "Canadian",
      "awards": ["Order of Canada", "The Economist Innovation Award"]
    }
  },
  {
    "name": "Dennis Ritchie",
    "languages": [
      {
        "name": "C",
        "year_created": 1972
      },
      {
        "name": "Unix",
        "year_created": 1969
      }
    ],
    "details": {
      "nationality": "American",
      "awards": ["Turing Award", "National Medal of Technology"]
    }
  },
  {
    "name": "Brendan Eich",
    "languages": [
      {
        "name": "JavaScript",
        "year_created": 1995
      }
    ],
    "details": {
      "nationality": "American",
      "awards": ["Webby Award"]
    }
  }
]

Traverse array and return specific fields

The following query selects all programming languages

jq '[ .[].languages[] | {name, year_created} ]' coders.json

[
  {
    "name": "C++",
    "year_created": 1983
  },
  {
    "name": "Python",
    "year_created": 1991
  },
  {
    "name": "Java",
    "year_created": 1995
  },
  {
    "name": "C",
    "year_created": 1972
  },
  {
    "name": "Unix",
    "year_created": 1969
  },
  {
    "name": "JavaScript",
    "year_created": 1995
  }
]

Drill down with jid

The Json Incremental Digger aka jid allows to drill down JSON actively using jq like queries.

For more detailed information, please visit jid on GitHub.

Installation

Install with apt
sudo apt install jid
Install with brew
brew install jid

Usage Example

We’re re-using the codes.json file from above:

hascode.com jid example
Figure 1. using jid to filter the coders.json file