Using if-then-else-end in jq to handle missing values
This is the command I use to pull the info I need:.results | .[] | {id, name: .general.name, platform: .general.platform, site: .general.site.name, ea_site: .extensionAttributes.[] |...
View ArticleCan jq unroll a list of objects by arbitrary key name?
I have a bit of a thorny JSON manipulation problem. I have half a mind to just write a Python program to do it, but I’m wondering if a well-written jq query can solve it more elegantly — partly for a...
View ArticleHow to join a string onto the output from an array
Let's say this is my output from an aws-cli command.{"imageIds": [ {"imageDigest": "sha256:9" }, {"imageDigest": "sha256:5" }, {"imageDigest": "sha256:46","imageTag": "latest" }...
View ArticleConvert a simple JSON object to a properties file
I have a simple JSON object and would like to convert it into a properties file in bash.Input: {"foo": "bar","abc": "def ghi"}expected output:foo="bar"abc="def ghi"
View ArticleUpdate package.json with jq
I am working on a web application that utilizes in-house npm packages.These packages have names that begin with the prefix @glen/The assignment is parse and to modify the package.json file by removing...
View ArticleConsolidating JOIN match results as opposed to taking "last matched" only
Using jq I am executing this query{places: [JOIN(INDEX(.thingGroups[]; .thingGroup); .places[]; .thingGroup[] // empty; add)]}against this data{"places": [ {"location": "wwc1","thingGroup": ["bs-1" ]...
View ArticleConvert JSON to CSV, repeating parent value
There's a lot of discussion to convert JSON to CSV with jq, but can't find my situation.2 points really blocking me :Get key and value of valuePerDay by rowSort valuePerDay keys to unsure values always...
View ArticleJQ: How to get just part of a JSON object? [duplicate]
How can I get my wanted output? I can't figure out how to preserve the object names (keys).I'm new to jq and I tried several flavors of jq's select/flatten/map/","/"keys as $k".../etc. but I'm not...
View ArticleMerge two JSON files with jq, adding integers
I have two JSON files of the form:{"xFruits": {"views": 163,"all": {"xApples": {"views": 28,"eats": 10,"discards": 17 } } },"xVegetables": {"views": 134,"all": {"xBeans": {"views": 29,"eats":...
View ArticleHow to debug jq errors for parsing AWS price API
I'm trying to parse out some of the AWS price API json results and noticed that I'm getting some errors on string and object validation, but can't figure out how to debug which object or string jq is...
View Articlecompare two json string failing while using jq [closed]
Hi I am using jq in my shell script to compare two json strings. the json string are present in two shellscript variable . the following is the codefunction compareJson() { local expectedJson="$1"...
View ArticleCheck the amount of traffic on server, and then detects if the traffic has...
I've written a script in the bash to connect to servers via SSH and check their traffic. If the traffic significantly decreases, the script will send an email to the address specified in the...
View ArticleHow can i use jq to format json to csv?
I am trying to format this json data to CSV format, but I get this error: error (at <stdin>:0): Cannot index array with string "time". Here is a short version of my json data:{"latitude":...
View ArticleSyntax when there is a space in the key
This is driving me nuts.I have a JSON that looks like this:{"gateways": [ {"DHCP": "On","External IPs": "46.244.46.66","Firewall": "On","NAT": "Off","Name": "gateway","Routed Networks": "photon,...
View Article| . + in jq meaning
I'm not sure what the dot and plus sign after a pipe mean, and I haven't been able to find anything on the internet about this. For example, when looking up a title in a Json object, I would write| . +...
View ArticleUsing JQ how to append entry to dictionary type array in JSON or create it if...
I have ideal JSON:{"environments":[ {"name":"test","release":"2.0" }, {"name":"prod","release":"1.0" }, ]}This file could be in any state:It can be empty file with just empty object { }It can have...
View ArticleJQ Cannot iterate over null
I am trying to create a jq that is dynamic in returning data.User Story: I have data with many fields and not named like I want. I want to be able to based on the data and schema transform the...
View ArticleMatch object with array key to exact values using jq
Match first object which has an array that contains exactly same values (it's should always be length of 2)Example:[ { "id": 242, "size": [500, 500] }, { "id": 234, "size": [500, 1920] }, { "id": 168,...
View ArticleConverting csv to json with jq
I'm currently practicing converting plain text to csv, and them csv to json. I need to do the conversion only with jq and basic Linux commands.I didn't have any major problems converting plain text to...
View ArticleUsing JQ query how to update propery inside two nested arrays?
I tried this for 2 days but can't figure it out in any way.This is my JSON:{"items": [ {"name":"itemA","bins":[ {"bin_id":"b1","count":"11" }, {"bin_id":"b2","count":"22" } ] },...
View Article