copy a value to another entry in the same element
There are plenty of examples of updating a value in a nested entry in jq, but I think I have a unique question, because the value I want to provide is already in another part of the same entry.Given...
View ArticleStoring output of a curl jq to environment variable in windows cmd
I want to save the output of curl -X GET "http://localhost:8080/test" ^| jq -r ".integrations.[0].id" to an environment variable within a jenkins batch command in Windows8 so that I can use it in...
View Articlejq to update key:value objects with matching strings at the begining
I need to update below json file values where key matches a substring.sample.json{"A": "a""re": {"jok/pok": ^20.0,"sok/dok": ^23.0,"jok/ssd": ^32.0}}now I need to append -dev to those key/values where...
View Articlejq: How to slurp mid-filter (convert separate json objects to an array)
I am parsing Elastic logs that look like$ cat my_log_file.txt:{"level": "INFO", "message": "foo"}{"level": "WARN", "message": "bar"}{"level": "WARN", "message": "baz"}Because they're one per line,...
View ArticleFiltering nested objects using JQ
For a given json:{"source_1": [ {"val1": "foo1","val2": "bar1" }, {"val1": "foo2","val2": "bar2" } ],"source_2": [ {"val1": "foo1","val2": "bar1" }, {"val1": "foo3","val2": "bar3" } ]}I would like to...
View ArticleHow can I reformat multiple levels of JSON using JQ?
I suspect I've set myself an impossible task, and have made some small progress looking at similar questions posted on this forum, but this one has me stumped.So here's my source JSON.{"totalCount":...
View ArticleProblem with JQ selecting specific keys based on selecting
I have a problem with JQ where I can't get the correct fields. I have don't so many tutorials but can't seem to get this. I am trying to get only the "cpu" for the "mysql" container, but I keep getting...
View Articlejq - print newlines while processing rows from an array
Suppose I have a json like this:{"records": [ {"id": 1,"name": "hello" }, {"id": 2,"name": "world" } ]}I could do this:$ jq -r '.records[] | "id: \(.id) name: \(.name)"' afile.jsonid: 1 name: helloid:...
View ArticleIs it possible to read gzip file directly with jq?
I'm reading huge json files with jq, something like:jq -r '[.a, .b, .time] | @tsv' file.txtthose files are coming as gz files and I spend each day 20 minutes just to gunzip them.I was wondering is it...
View ArticleHow to append records to a json object file in bash
I need to loop through a dictionary and append records to a json object file option.jsonthe code I have isfor K in "${!MYMAP[@]}"; do opt="{ \"OptionName\":\"${K}\", \"Value\":\"${MYMAP[$K]}\" }," echo...
View ArticleHow to get jq to output a long dataset?
Suppose I have this ndjson:{"id": "one", "colors": [{"color": "blue"}, {"color": "red"}]}{"id": "two", "colors": [{"color": "green"}]}How do I get the output below?one blueone redtwo greenHere is a...
View ArticleHow to combine the sequence of objects in jq into one object?
I would like to convert the stream of objects:{"a": "green","b": "white"}{"a": "red","c": "purple"}into one object:{"a": "red","b": "white","c": "purple"}Also, how can I wrap the same sequence into an...
View Articlejq: group and key by property
I have a list of objects that look like this:[ {"ip": "1.1.1.1","component": "name1" }, {"ip": "1.1.1.2","component": "name1" }, {"ip": "1.1.1.3","component": "name2" }, {"ip": "1.1.1.4","component":...
View Articleexport json output to environment variable missing commas in Bash
[{"Availab]ilityZone": "ap-east-1a" "Description": "AWS_FOO" "Groups": [ {"GroupName": "AWS_FOO" "GroupId": "sg-AWS_FOO" } {"GroupName": "AWS_FOO" "GroupId": "sg-AWS_FOO" } ] } {"Availab]ilityZone":...
View ArticleUsing jq to count
Using jq-1.5 if I have a file of JSON that looks like[{... ,"sapm_score":40.776, ...} {..., "spam_score":17.376, ...} ...]How would I get a count of the ones where sapm_score > 40?Thanks,DanUpdate:I...
View Articlejq to set several explicit properties at once
In a very simplified senes, I would like to take an existing JSON object and use jq to add/update two additional values to it. For exampleStartResult{}{"a": 1, "b":2}{"a":42}{"a": 1,...
View ArticleEscape field name in jq that contains '@' and '-'? [duplicate]
Input JSON:{"abc": {"@def-ghi": "value1","xyz": "value2" }}And I'm trying to get value for field @def-ghi. ➜ $?=0 ➤ echo '{"abc": {"@def-ghi": "value1", "xyz": "value2"}}' | jq '.abc.xyz'"value2"➜ $?=0...
View ArticleCorrectly escape environment variable to be used in Jenkins jq script
I have the following JSON:{"defaultOptions" : {"environmentVariableEntries" : [ {"key" : "OS_VERSION","value" : "13" } ] }}on Jenkins I have a step that writes some environment variables and in another...
View ArticleHow to udpate a value in a nested and partly flattened object with jq?
I need to override the property version with the value of image. The problem is, that the json document can have several forms, whereby parts of the nesting can be flattened:Example Document...
View ArticleWhy neither branch of if-statement is reached?
Since .value is true, which does not have an field message, I thought .message? should be evaluated to false. Then "Y" should be printed. Can you help me understand why neither "X" nor "Y" is printed?$...
View Article