jq to replace text directly on file (like sed -i)
I have a json file that needs to be updated on a certain condition. Sample json{"Actions" : [ {"value" : "1","properties" : {"name" : "abc","age" : "2","other ": "test1" } }, {"value" :...
View ArticleDetermine if any value exists matching a filter expression while treating an...
I'm trying to determine whether a jq expression refers to no items at all, without collapsing null and empty.As I understand it, .foo? should be identical to try .foo catch empty. Because catch empty...
View ArticleHow to filter list based on prefix list?
I have a list of hostnames and I want to filter out all hostnames that end in any of a given List of domains. For example for the hostnames...
View ArticleSelecting parent objects based on nested child properties
I have a JSON document as a result of scanning a DVD. It contains a TitleList array, each entry of which contains a ChapterList array, each entry of which has a Duration object. I want to select 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 Articlehow to get list of available ios simulators?
i want to list available ios simulators as in below format ( iOS version should take from JSON key ){"name": "iPhone 5s (11.4)","udid": "FB6B3F7F-E6CD-4F64-8EC4-6C07C86A25C8"}{"name": "iPhone 6 Plus...
View ArticleFilter empty and/or null values with jq
I have a file with jsonlines and would like to find empty values.{"name": "Color TV", "price": "1200", "available": ""}{"name": "DVD player", "price": "200", "color": null}And would like to output...
View ArticleHow 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:$ cat json.txt | jq '.name'"Google"How can I pipe this into another...
View Articleget label value from docker inspect [duplicate]
I had problem to get the value from the map list due to the key has "." inside.docker inspect jenkins Config: { .."Labels": {"com.docker.compose.config-hash":...
View ArticleConvert JSON file to CSV using jq, expanding nested array data in multiple...
I need to convert a JSON file to CSV in a bash script, this a sample file:{"total": 1,"jobs": [ {"deviceData": {"deviceId": "ad7bcba0","name": "Device name","serialNumber": "Serial","productNumber":...
View ArticleHow to convert a string to an integer in a JSON file using jq?
I use jq to transform a complex json object into a tinier one. My query is:jq 'to_entries[]| {companyId: (.key), companyTitle: (.value.title), companyCode: (.value.booking_service_code)}'...
View ArticleHow 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 :...
View ArticleFiltering out JSON properties where keys do not match length
I have JSON that looks like:{"18003432343": ....,"18005553332": ....,"1-3-2025 10:36:41_08941100 AM": ....,"1-3-2025 11:36:41_08941100 AM": ....}I would like to use JQ to filter out all keys where the...
View ArticleConverting JSON to JSONL without losing original object structure
I have JSON that looks like:{"18003432343": {"04:00:25": {....},"12:00:25": {....}, }, "18005553332": {"18:11:25": {....},"23:00:25": {....}, }}If I convert the above to JSONL using:jq -c '.[]'...
View ArticleGet 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 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