Resources
- Try jq online: https://jqplay.org/#
- Interactive JSON filter : https://github.com/ynqa/jnv
Basis
Usage
cat myFile.json | jq
jq myFile.json
jq <<< { "player": { "name": "apple", "color": "blue" } }
Flags
-rOutput raw strings (without the quotes).
Filter
Filter JSON Array
["myPlayer1", "myPlayer2", "myPlayer3"]
jq '.[]' myFile.jsonReturn elements line by line (without
[ ]).jq '.[2]' myFile.jsonReturn an element by its ID.
jq '.[2:12]' myFile.jsonReturn a subset of elements.
Filter JSON Object
{
"player": {
"name": "myPlayer",
"color": "blue"
}
}
jq '.player.name' myFile.jsonReturn the a property.
jq '.player | {name,color}' myFile.jsonReturn the multiple properties.
jq '.player | select(.player_class == "knight")' myFile.jsonReturn
playerthat have the propertyplayer_classset toknight.
jq '.player | keys' myFile.jsonReturn the keys of
player(nameandcolor).jq '.player | length' myFile.jsonReturn the length of
player(here the number of properties is 2).
