Resources


Basis


Usage

cat myFile.json | jq

jq myFile.json

jq <<< { "player": { "name": "apple", "color": "blue" } }


Flags

-r
Output raw strings (without the quotes).

Filter


Filter JSON Array

["myPlayer1", "myPlayer2", "myPlayer3"]

jq '.[]' myFile.json
Return elements line by line (without [ ]).

jq '.[2]' myFile.json
Return an element by its ID.

jq '.[2:12]' myFile.json
Return a subset of elements.


Filter JSON Object

{
  "player": {
    "name": "myPlayer",
    "color": "blue"
  }
}

jq '.player.name' myFile.json
Return the a property.

jq '.player | {name,color}' myFile.json
Return the multiple properties.

jq '.player | select(.player_class == "knight")' myFile.json
Return player that have the property player_class set to knight.

jq '.player | keys' myFile.json
Return the keys of player (name and color).

jq '.player | length' myFile.json
Return the length of player (here the number of properties is 2).