Updating a nested object in json and saving it back to original
I have big json, where i am renaming a nested object .module.home.[].list member from object_old to object_new and then deleting the object_old key.cat out.json{ ... {"objecta": {"field1": 1,"field2":...
View Articlejq rename nested json key and place under same key
I want to rename nested json key and keep under same schema.Input:"properties": {"name": "Ram","age": "17","department": "Sony" }Code : jq '[.["properties.company"] = .properties.department|...
View Articlejq - return array value if its length is not null
I have a report.json generated by a gitlab pipeline.It looks...
View Articledocker image pull stedolan/jq fails on deprecation
Error seen is:+++ docker run --rm -i stedolan/jq '.architectures.x86_64.artifacts.qemu.formats["qcow2.gz"].disk.location'+++ tr -d '"'Unable to find image 'stedolan/jq:latest' locallylatest: Pulling...
View ArticleConvert JSON array of key/value pairs into values with a comma seperator...
I have the following JSON.{"foo": [ {"bar": "baz" }, {"bar": "baz" }, {"bar": "baz" } ]}I'd like to convert this using jq into the following"baz", "baz", "baz"How do I do this using jq without any...
View Articlemerge 2 json arrays using ansible or jq
So I have 2 json array filesone with some simple data (could be any number of servers): [ {"playbook": "simplerun.yml","server": "abc","status": "success" }, {"playbook": "simplerun.yml","server":...
View ArticleCreate one big object from a list of objects using jq
Okay so I have blob of data like so ...[{"sys_replace_on_upgrade": "false","initial_state": "false","sys_mod_count": "0","sys_updated_on": "2020-09-02 13:48:39","sys_tags": "","state_label":...
View Articleselect based on values in sub-object array
I'm trying to automate the process for updating AWS Lambda layers and the functions that use them. To get a list of functions that use a particular layer I'm parsing the JSON output of the AWS CLI when...
View ArticleHow to merge arrays within JSON object
Given a JSON object{"foo":["barfoo"],"bar":["foobar"]}I would like to merge both arrays, i.e. output:barfoofoobarObviously I can list either array using, e.g. jq -r .foo[] but I'm not sure how to go...
View ArticlePrint input element even when capture() fails to match expression
I'm trying to extract info on certain specific dependencies from the output of DTrack's /v1/project endpoint.The API returns data in the format:[{"name": "project name","classifier": "LIBRARY |...
View ArticlePassing bash variable to jq
I have written a script to retrieve certain value from file.json. It works if I provide the value to jq select, but the variable doesn't seem to work (or I don't know how to use it).#!/bin/sh#this...
View ArticleHow to merge the values from the top-level property to each item in the array?
Here's my sample JSON file:{"Schedules": {"Days": ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday" ],"Times": ["8:00 AM", "9:00 AM", "10:00 AM"] },"Servers": [ {"Name":...
View ArticleHow to update json with variable array using bash script
I have a json file test.json with below format:{ "environments": {"egress": [ ] }}I want to add objects under egress field with multiple variable values. I have written a bash script test.sh with below...
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 ArticleConvert json to Markdown Table in bash
I am trying to convert the below json to a markdown table(GitHub docs(.md file)), however not able to do...
View ArticleHow to extract a list of URLs from JSON using jq
Microsoft Clarity returns JSON. I am able to extract the following portion of JSON using JQ:$ echo $JSON | jq '.[] | select(.metricName == "PopularPages") | .[]'"PopularPages"[ {"url":...
View ArticleHow to use jq in linux for multiple files?
I am trying to convert SAFECAST API JSON to a CSV suitable for spreadsheet programs like Excel etc. to prepare some data summaries etc. I have semi-manual WGET script to download several JSON files...
View Articlejq returns null or error when parsing json response [duplicate]
When parsing a json response using jq run from cmd.exe on a Windows 10 machine, I always get either a null response or an error when trying to get a value present in the JSON.Here is the curl:curl -X...
View ArticleExtract (parse) specific strings from a ansible playbook output - bash [closed]
I have the following output from a ansible playbook execution.PLAY [SonarQube on-boarding] ***************************************************TASK [Create file directory]...
View Articlehow to select Any of available fields with jq?
I'm trying to filter some journald logs which might have some-what similar information in different keys.journalctl -o json | head -n 1000 | jq '.UNIT, .USER_UNIT, ._SYSTEMD_UNITThose 3 keys might have...
View Article