Questions tagged [jq]

Questions about the command line JSON processing tool jq.

Filter by
Sorted by
Tagged with
2
votes
3answers
1k views

How do I invoke jq inside awk?

Essentially I have a file.log as follow blah blah blah blah Hello world | {"foo": "bar"} blah blah Hello earth | {"foo1": "bar1"} Now my goal is to write some shell commands to have desire output ...
-3
votes
2answers
137 views

how to capture the properties tag from json file [duplicate]

this is very short list of my json file: "slider-client" : { "properties_attributes" : { }, "properties" : { } } }, { "spark2-hive-site-override" : { "properties_attributes" : { }, ...
2
votes
2answers
994 views

Use JQ to generate CSV from knife search

JQ looks like a great tool, but I'm struggling with it. Here is what I am trying to do: Extract just the values from this chef knife search and generate a CSV. given this command and output: knife ...
0
votes
1answer
99 views

Should I include code to install the packages that my script requires?

I have a script built just a way to learn bash and it uses jq for json parsing suppose someone else downloads it and runs the file, will bash automatically prompt the user to install jq or should I ...
5
votes
1answer
1k views

jq returning full result after operation

I'm adding a property to a JSON string with result=$(jq -c ".docs[$docIndex] + { \"value\": \"value\" }"<<<"$fileContent") Where the JSON inside $fileContent is { "docs": [ { ...
3
votes
1answer
574 views

bash string concatenation failed

Important note: I'm using Cygwin to run this script. I got a json string by executing result=$(jq -c ".docs[$docIndex] + { \"_rev\": \"rev\" }"<<<"$fileContent") Here is the JSON I get: {"...
3
votes
1answer
6k views

bash add property using variable with jq

To add a property to a JSON text I manage to use result=$(jq -c '.docs[0] + { "value": "someValue" }'<<<"$fileContent") But if I want to replace "someValue" by a variable: result=$(jq -c '....
0
votes
1answer
1k views

equal comparison on jq variable

I have a bash script that run a curl request and output the status via jq. I get the status as expected but when I compare the status it's always returning "non-equal" value, even if the value is ...
2
votes
1answer
1k views

Why can't I delete these array items in jq?

Given the command: echo "[\"tag1\", \"[[Super\", \"Duppa\", \"Database\", \"Analyst]]\", \"tag2\"]" | jq -f ~/somefilter.jq And the filter: def hasOne(x): x | (startswith("[[") or endswith("]]") ); ...
4
votes
2answers
6k views

Split a sting field into an array in jq?

I have a json array returned from curl that looks like this: [ { "title": "Some Title", "tags":"tagA tag-B tagC" }, { "title": "Some Title 2", "tags":"tagA tagC" }, ... ] I'd like ...
7
votes
1answer
7k views

combine pipe and redirect on curl and jq

If i curl to some site I can get straight json: curl http://httpbin.org/ip { "origin": "37.77.126.22"} to beautify, i do: curl http://httpbin.org/ip | jq { "origin": "37.77.126.22" } to ...
9
votes
3answers
23k views

Setting jq output to a Bash Variable

I'm using curl to get JSON back from a rest api like this: content=$(curl -s -X GET -H "Header:Value" http://127.0.0.1:8200/etc) echo "${content}"| jq -r '.data.value' which produces the value I ...
-2
votes
1answer
263 views

Extracting text with jq [closed]

How can I use jq to extract the object with id 11 from the following JSON, in order to process the CPU Package Temperature? { "id":0, "Text":"Sensor", "Children":[ { "id":1, "Text":"PC15029", "...
0
votes
2answers
3k views

Bash - loop through files and pull JSON value from corresponding keys in a master key file

I'm trying to make a bash script that loops through a file that contains a list of files (so it goes through each one of these files). While the files are open, I want to use another program (jq) to ...
2
votes
2answers
933 views

Using JQ to get simple delimited output

How might one turn this: { "write": { "out": 0, "available": 128, "totalTickets": 128 }, "read": { "out": 7, "available": 249, "totalTickets": 256 } } Into 0 128 128 ...
1
vote
1answer
486 views

Echoing text and executing a command with jq

I have a command that spews json to stdout like so: foo inf --db { "Name": "A rose by any any other", "Config": { "DBHost": "abc.efg.us-east-1.rds.amazonaws.com", "DBName": ...
4
votes
1answer
5k views

Wildcard in jq with comparatives

Piping in some json, I want to be able to add a wildcard to the comparative, so: curl example.com/json | jq 'select(.[].properties.type == "dev*")' So it would print out anything with a type that ...
13
votes
3answers
20k views

Merge jq output into a comma separated string [duplicate]

I am trying to curl some URL which returns a json file, then I want to parse hosts from it and create a comma separated string. I have the first part working curl -s -u "admin:admin" -H "X-...
0
votes
1answer
623 views

jq capture - how to properly key with captured string

I routinely use lshw -json to abstract system data on Linux hosts. In the current scenario, I've extracted network data from lshw via lshw -c network -json and have need of extracting, further, data ...
2
votes
1answer
8k views

Filtering JSON request with JQ and bash scripting

I'm requesting a JSON from Twitch with: curl --silent -H 'Accept: application/vnd.twitchtv.v3+json' -X GET https://api.twitch.tv/kraken/streams/$1 where $1 is the input I send for my function. Now ...
6
votes
1answer
17k views

Editing a child JSON element value with jq

I'm trying to use jq in order to change a child's value. For instance, I want to change the value of "test2" from ["yo", "bye"] to ["hi"]. { "title": "hello", "body": { "test1": 123, ...
27
votes
1answer
18k views

How to prettyprint json using jq standalone?

Currently, when I want to pretty-print a json file using jq, I use: cat file.json | grep jq . Yet I would expect for jq to accept a file name as argument without having to fallback on cat. The man ...
57
votes
6answers
96k views

Using jq to extract values and format in CSV

I have the below JSON file: { "data": [ { "displayName": "First Name", "rank": 1, "value": "VALUE" }, { "displayName": "Last Name", "rank": 2, ...