How to use `jq` to obtain the keys
My json looks like this : {"20160522201409-jobsv1-1": {"vmStateDisplayName": "Ready","servers": {"20160522201409 jobs_v1 1": {"serverStateDisplayName": "Ready","creationDate":...
View ArticlePass bash variable to jq filter and echo the whole command to another variable
I have a sample json like this /tmp/test.json{"foo" : "val1","bar" : "val2"}Setting the key in a variablekey=foocat /tmp/test.json | jq --arg k $key '.[$k]'# Output is fine"val1"Now if I want to store...
View ArticleConvert human readable time to epoch inline with jq for time comparison
I am writing a bash script to compare VM creation date to an epoch time gathered in a previous step to see what VMs were recreated before a certain date. These are bosh vms which gives human readable...
View Articlejq filter to remove field value if contains element from list
This is somewhat similar to this: jq: how to filter an array of objects based on values in an inner array? but extendedI have a list of values I want to filter out but it is not 1:1 match. It's...
View ArticleDelete Pod without restarting other resources/object
I currently have this bash script that do cleanup obsolete resources for deployment, services, and configmaps. when I try to add the kubectl delete pod on the script, then it will delete all the...
View ArticleUsing jq to group-concat fields by field name prefix
I have a json file like this, I woiuld like to have a jq based solution to transform this:{ ... fields1 ..."any": [], "other": 1,"aa.2": "second.", "aa.1": "first ", ... fields2 ..."bla.bla.0": "aa",...
View ArticleHow to recursively print the path of all keys in jq
I'd like to get a list of all paths available in a JSON document, just to get an idea of the layout of a big json document.One liners preferred, of course a big jq/python program can do the...
View Articlejq: assigning to computed property of an object
I'm trying to get jq to generate an object whose keys are computed.This didn't work:$ jq -n --arg key foo '{} as $o | $o[$key] = 42'jq: error (at <unknown>): Invalid path expression near attempt...
View ArticleHow to increase depth limit of jq?
When trying to minify a deeply nested JSON file (~10k deep) using jq I got a parse error:$ jq -c . <input.json >minified.jsonparse error: Exceeds depth limit for parsing at line 227263, column...
View ArticleGet a specific key and value from JSON
I need something very simple. Sorry I am not familiar with jq and a top novice.{"pets": [ {"name": "Purrsloud","species": "Cat","favFoods": ["wet food","dry food","<strong>any</strong>...
View ArticleСreating multilevel json with the jq utility in a bash script
I get the contents of a text file into an array and then sequentially get the elements of the array and try to add the elements to the json:#!/bin/bashJSON=$(jq -n '')readarray -t array <...
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, as shown below:$ cat json.txt | jq '.name'"Google"How can I pipe this...
View ArticleOutput from Chrome Window / Tab Manager extension: Selecting a Window and...
People,Here is the head of an exported file:{"tabfern": 42,"version": 1,"tree": [ {"raw_title": "OpenAI","tabs": [ {"raw_title": "OpenAI","raw_url": "https://openai.com/","raw_favicon_url":...
View ArticleJQ: Select multiple conditions
I have a json and at the moment using select to get only the data which match one condition, I need to filter based on more conditions.For e.g:.[] | select((.processedBarsVolume <= 5) &&...
View Articlejq split jsonlines file into two [valid and nonvalid lines]
I frequently receive application logs from journald. The application itself logs with jsonlines, but sometimes I got invalid lines, if...:something is written to stderr like Listening for transport...
View Articlehow to use jq to filter select items not in list?
In jq, I can select an item in a list fairly easily:$ echo '["a","b","c","d","e"]' | jq '.[] | select(. == ("a","c"))'Or if you prefer to get it as an array:$ echo '["a","b","c","d","e"]' | jq...
View ArticleSplit valid and invalid JSONL records into two files using JQ
I frequently receive application logs from journald. The application itself logs with jsonlines, but sometimes I got invalid lines, if...:something is written to stderr like Listening for transport...
View ArticleHow to find and merge two json objects in a bash script using jq
I need to merge two json objects by key value in a bash script:It is necessary to find by key (MAC address) the corresponding object (value) and add to its pairs the key: value pair of another...
View Articlewhile loop removes quotes escapes making jq fail to parse json [duplicate]
"$response":[{"word":"world","phonetic":"/wɝld/","phonetics":[{"text":"/wɝld/","audio":"https://api.dictionaryapi.dev/media/pronunciations/en/world-ca.mp3","sourceUrl":"https://commons.wikimedia.org/w/...
View ArticleHow to only update a specific object in json using jq
I read a json from a file, manipulated one of the fields such as below and got the output on terminalcat list.json | jq ".module.home.[].names | map(.long=\"$long\")"However, the original file i.e....
View Article