jq - Parse JSON file
by
Jeremy Canfield |
Updated: February 25 2024
| jq articles
Let's say you have the following in a file named my.json.
{
"data": {
"greeting": [
{
"foo": "hello"
},
{
"foo": "world"
}
]
}
}
Here is how you can parse my.json using jq on a Linux system.
~]$ jq my.json
{
"data": {
"greeting": [
{
"foo": "hello"
},
{
"foo": "world"
}
]
}
}
To parse the "data" key.
~]$ jq .data my.json
{
"greeting": [
{
"foo": "hello"
},
{
"foo": "world"
}
]
}
To parse the data and then greeting key.
~]$ jq .data.greeting my.json
[
{
"foo": "hello"
},
{
"foo": "world"
}
]
Or like this, since the greeting key contains a list.
~]$ jq ".data.greeting[]" my.json
[
{
"foo": "hello"
},
{
"foo": "world"
}
]
Did you find this article helpful?
If so, consider buying me a coffee over at