Get all objects with attribute that does not have any of the provided substrings
Consider this basic JSON file:{"list": [ {"random": 123,"fruits": "pineapple" }, {"random": 42,"fruits": "peach" }, {"random": 87,"fruits": "banana orange" } ]}How do I get all objects in list that...
View ArticleIgnore Unparseable JSON with jq
I'm using jq to parse some of my logs, but some of the log lines can't be parsed for various reasons. Is there a way to have jq ignore those lines? I can't seem to find a solution. I tried to use the...
View ArticleUse jq to replace many values with variable values
Using jq, is it possible to replace the value of each parameter in the sample JSON with the value of the variable that is the initial value?In my scenario, Azure DevOps does not carryout any kind of...
View ArticleCombine JSON to YAML list
In a GitLab pipeline job I have multiple JSON files. I need these JSON files as YAML and I would like to have them in the same YAML file as a list. They do not always have the same keys.I would like...
View ArticlePassing a regular expression as an argument to jq
When I write a literal query as follows:jq '.[] | select(.translated | test("^ש[\u05b0-\u05c7]*ל[\u05b0-\u05c7]*ו[\u05b0-\u05c7]*ם$"))' dict-he-en.jsonI get exactly the results I expect. When I try to...
View ArticleHow to use jq to output JSONL (one independent JSON object per line)
My request sounds trivial but I could not find a way to do it. I have as input an array of JSON objects:[ {"foo": 1,"bar": 2 }, {"foo": 3,"bar": 4 }, (...)]and I want as output the JSONL version of the...
View Articleusing jq how to sort array of object
There is an array of json object, using jq how to check if an object exists if so returns the true else falseI tried this but getting errorcat fruits.json | jq '.fruits[]| sort_by(.version)'I would...
View ArticleUsing jq, how can I limit values based on a key
For an input file that looks like this:{"employees": [ {"number": "101","tags": [ {"value": "yes","key": "management" }, {"value": "joe","key": "login" }, {"value": "joe blogs","key": "name" } ] },...
View ArticleHow to limit properties of a JSON object given array of property names using JQ?
Assuming I have the following JSON object (which is just an example):{ "foo": 1, "bar": 2, "baz": 3 }And the following JSON array (another example):["foo", "baz"]How could I use jq to output the...
View Articleget the first (or n'th) element in a jq json parsing
I can get the 1st element in a JSON inside []$ echo \'[{"a":"x", "b":true}, {"a":"XML", "b":false}]' | \ jq '.[1]'{"a":"XML","b": false}But if the json is already disassembled (for instance, after...
View ArticleConvert JSON lines to JSON array using jq
Firstly, I'm new to jq, like 1 day new, I'm also new to JSON, I'm an SQL guy so I'm learning fast but can't get my head around this ... so please bear with me.I'm running Windows, using jq v1.5 on...
View ArticleWhat is the internal, inverse operation of .[] in jq? or How to construct an...
echo '[ {"a":1}, {"b":2}, {"c":3} ]' | jq '.[] | revert_op 'What can we replace revert_op with to get this?[ {"a":1}, {"b":2}, {"c":3} ]jq -s '.' does the job, but this is a CLI option, and I want a...
View ArticleHow to process subelements of array created by split?
I am parsing output from the docker container ls --format json command and trying to process and format the content to keep only what I need./usr/bin/docker container ls --format json | jq ". |...
View ArticleAdd new element stored in a variable to existing JSON array with jq
I am working on creating an adaptive card dynamically. I have the skeleton on the card in JSON and I want to add entries to it (each entry will be a JSON object inside the "body" of the below schema)....
View ArticleUsing jq how to correctly read a pair containing a backslash character?
I have a script with reading from json file in this way:jq -c '.[]' input.json | while read pair; do echo "$pair" | jq -r '.[0]'done;The above throws `parse error: Invalid numeric literal at line 1,...
View ArticleHow do I sum all numbers from output of jq
I have this command that I would like to sum all the numbers from the output. The command looks like this$(hadoop fs -ls -R /reports/dt=2018-08-27 | grep _stats.json | awk '{print $NF}' | xargs hadoop...
View ArticleHow 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...
View Article