Welcome to the jq playground! This sandbox is designed to help you try out jq, a powerful tool for working with JSON.
First, add your JSON data to the data.json
file below:
{
"store": {
"books": [
{ "title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "price": 10.99, "genre": "fiction" },
{ "title": "Clean Code", "author": "Robert C. Martin", "price": 38.95, "genre": "non-fiction" },
{ "title": "The Pragmatic Programmer", "author": "Andrew Hunt", "price": 42.99, "genre": "non-fiction" },
{ "title": "1984", "author": "George Orwell", "price": 8.99, "genre": "fiction" }
],
"music": [
{ "artist": "The Beatles", "album": "Abbey Road", "price": 19.99, "genre": "rock" },
{ "artist": "Miles Davis", "album": "Kind of Blue", "price": 15.49, "genre": "jazz" }
]
}
}
Then create jq filters and see the response:
jq '
.store |
{
"summary": (
[.books[], .music[] | select(.price <= 20)] |
group_by(.genre) |
map({
genre: .[0].genre,
total_items: length,
total_price: map(.price) | add
})
)
}' data.json
To learn how to use jq, see this interactive tutorial.