Questions tagged [jq]

jq is a sed-like tool for JSON data – you can use it to slice, filter, map, and transform structured data with the same ease that sed, awk, grep and friends lets you play with text.

jq is a succinct programming language for querying and manipulating JSON data or plain text files. You can use it to slice, filter, map, and transform structured data with the same ease that sed, awk, grep and friends let you play with textual data. jq is stream-oriented and uses the pipe symbol | to connect filters familiarly.

Resources

6401 questions
1247
votes
46 answers

Parsing JSON with Unix tools

I'm trying to parse JSON returned from a curl request, like so: curl 'http://twitter.com/users/username.json' | sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' The above splits the JSON into…
auser
  • 13,808
  • 4
  • 21
  • 15
635
votes
2 answers

How to remove double-quotes in jq output for parsing json files in bash?

I'm using jq to parse a JSON file as shown here. However, the results for string values contain the "double-quotes" as expected, as shown below: $ cat json.txt | jq '.name' "Google" How can I pipe this into another command to remove the ""? so I…
Chris F
  • 14,337
  • 30
  • 94
  • 192
465
votes
5 answers

Select objects based on value of variable in object using jq

I have the following json file: { "FOO": { "name": "Donald", "location": "Stockholm" }, "BAR": { "name": "Walt", "location": "Stockholm" }, "BAZ": { "name": "Jack", "location":…
Daniel
  • 12,445
  • 4
  • 21
  • 18
463
votes
8 answers

Using jq to parse and display multiple fields in a json serially

I have this Json { "users": [ { "first": "Stevie", "last": "Wonder" }, { "first": "Michael", "last": "Jackson" } ] } Using jq I'd like to display first and last…
San
  • 5,051
  • 3
  • 16
  • 12
451
votes
3 answers

How to filter an array of objects based on values in an inner array with jq?

Given this input: [ { "Id": "cb94e7a42732b598ad18a8f27454a886c1aa8bbba6167646d8f064cd86191e2b", "Names": [ "condescending_jones", "loving_hoover" ] }, { "Id":…
Abe Voelker
  • 30,124
  • 14
  • 81
  • 98
370
votes
7 answers

How to count items in JSON object using command line?

I'm getting this kind of JSON reply from a curl command: [ { "cid": 49, "pyn": "yi4", "hans": "亿", "hant": "億", "tid": 68, "l10n": "cent million", "pid": 1, "pos": "num", "pos_txt": "" }, { "cid": 50, …
Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178
291
votes
10 answers

How to install JQ on Mac on the command line?

I need to know the most efficient way of installing JQ on Mac (El Capitan). The code is downloaded to my Mac but I would like to know how I can install and operate it via the command line.
Ross Brannigan
  • 3,051
  • 2
  • 10
  • 3
248
votes
4 answers

How do I select multiple fields in jq?

My input file is newline delimited JSON (ndjson) looking something like this: { "login": "dmaxfield", "id": 7449977, ... } { "login": "dmaxfield", "id": 7449977, ... } I can get all the login names with this : cat members | jq…
J. Groesser
  • 2,547
  • 3
  • 11
  • 4
248
votes
9 answers

How to get key names from JSON using jq

curl http://testhost.test.com:8080/application/app/version | jq '.version' | jq '.[]' The above command outputs only the values as below: "madireddy@test.com" "2323" "test" "02-03-2014-13:41" "application" How can I get the key names instead…
Ezhilan Mahalingam
  • 2,838
  • 3
  • 16
  • 16
242
votes
11 answers

Passing bash variable to jq

I have written a script to retrieve certain value from file.json. It works if I provide the value to jq select, but the variable doesn't seem to work (or I don't know how to use it). #!/bin/sh #this works *** projectID=$(cat file.json | jq -r…
asidd
  • 2,961
  • 2
  • 10
  • 9
242
votes
2 answers

JQ: Select multiple conditions

I have a json and at the moment using select to get only the data which match one condition, I need to filter based on more conditions. For e.g: .[] | select((.processedBarsVolume <= 5) && .processedBars > 0) How I can do this ?
Andrei Colta
  • 2,542
  • 2
  • 10
  • 4
238
votes
2 answers

How to use `jq` in a shell pipeline?

I can't seem to get jq to behave "normally" in a shell pipeline. For example: $ curl -s https://api.github.com/users/octocat/repos | jq | cat results in jq simply printing out its help text*. The same thing happens if I try to redirect jq's…
mgalgs
  • 15,671
  • 11
  • 61
  • 74
229
votes
8 answers

How to merge 2 JSON objects from 2 files using jq?

I'm using the jq tools (jq-json-processor) in shell script to parse json. I've got 2 json files and want to merge them into one unique file Here the content of files: file1 { "value1": 200, "timestamp": 1382461861, "value": { …
Janfy
  • 2,466
  • 2
  • 20
  • 17
213
votes
9 answers

How to convert arbitrary simple JSON to CSV using jq?

Using jq, how can arbitrary JSON encoding an array of shallow objects be converted to CSV? There are plenty of Q&As on this site that cover specific data models which hard-code the fields, but answers to this question should work given any JSON,…
outis
  • 75,655
  • 22
  • 151
  • 221
196
votes
3 answers

How do I update a single value in a json document using jq?

Appologies if I've overlooked something very obvious; I've just found jq and am trying to use it to update one JSON value without affecting the surrounding data. I'd like to pipe a curl result into jq, update a value, and pipe the updated JSON to a…
STW
  • 44,917
  • 17
  • 105
  • 161
1
2 3
99 100