bash + jq: trying to read two json files and structure a new one
I have the following json files:common.json{"common": {"Hello": "ABC" },"east": {"Direction": "East" },"west": {"Direction": "West" }}pi.json{"common": {"MyUri": "www.myuri.com" },"east": {"App-Env":...
View Articlejq not printing full string with spaces in Bash script [duplicate]
Here is my structure:I am trying to print some values in a JSON file. Here is the service-data.json:{"service_name": "nphies-support.service","description": "nphies-support-service Spring Boot...
View ArticleSelect one of several subattributes dependent on its content
I have a JSON Output describing the configuration of an OPNSense Firewall.I want to condense the output into something more useful. Consider the following element of a list of VLANs[ {"key":...
View ArticleDelete keys in nested json file on windows shell script
I want to delete some keys and its values in a nested json file on windows in a shell .cmd script, but get errors.Looks like a quoting issue and more.Input file:{"account_tracker_service_last_update":...
View ArticleHow to execute multi attribute selection jq command on a external json file...
I'm attempting to use windows cmder to execute jq commands for command-line JSON processor to transform and output existing JSON files I have saved.Given the the sample json[ {"firstName":...
View ArticleHow to merge multiple json files in a directory with jq or any tool?
I am trying to merge all json files in a directory (can be many).I know that if there are only 2 files, I can use jq -s . file1.json file2.json. But when I tried to use the a wild card like jq -s ....
View ArticleIssue while parsing JSON response using jq
curl -H "Authorization: token " -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos///pulls?state=closed&per_page=100&page=1" | jq -r '.[] | [.number, .created_at, .state,...
View ArticleHow to catch "$variable is not defined" in jq?
Let's pretend I'm running something like this:jq -nr --arg target /tmp \'(["echo","Hello, world"]|@sh)+">\($target)/sample.txt"' \| shEverything is fine unless I forgot to pass variable $target:$ jq...
View Articlejq - How to iterate through keys of different names
I've got JSON that looks like this {"keyword1": {"identifier1": 16 },"keyword2": {"identifier2": 16 }}and I need to loop through the keywords to get the identifiers (not sure if I'm using the right...
View ArticleHow do I assign the output of jq to variables?
I am attempting to parse NOAA NWS json data with jq. My last computer class was as a senior in high school, '67-68 semester. Be gentle.I have figured out how to filter the data I want, but I'd like it...
View ArticleChanging parent value, when child meet specific conditions
I'm currently struggling with some jq, hope somebody can help.Given is the following JSON structure:[ {"id": "100","input": "ChecklistState","value": "-","sub": [ {"id": "110","input": "Text","value":...
View ArticleExporting JSON to environment variables
If I have a JSON like this,{"hello1": "world1","testk": "testv"}And I want to export each of these key-value pairs as environment variables, how to do it via shell script? So for example, when I write...
View ArticleHow to get JQ to retain comma separation between matched records in the output
I'm attempting to use windows cmder.exe (or standard command prompt) to execute jq commands for command-line JSON processor to transform and output existing JSON files I have saved. I've had success...
View ArticleJQ transformation
Suppose I have a json object like this {"name": "abc","version": "1234"}{"name": "xyz","version": "6789"}I want it to transform it to{"abc": "1234","xyz" : "6789"}I have tried map and reduce. But cant...
View ArticleFilter json to keep sub-content that matches a given pattern anywhere in the...
Suppose I have a json file. I want to filter this file to only output content where a given pattern appears in anywhere in the full path or leaf node value. For example, suppose the json file has below...
View Articlejq select value from array
I have the following JSON file with example values:{"files": [{"fileName": "FOO","md5": "blablabla" }, {"fileName": "BAR","md5": "alaldlafj" }]}Now what I want is to return the md5 value where for...
View ArticleReplace nested object with an object from another file in JQ
I have a json file that has the following structures{"a":"aval","b":{},"c":"cval"}I have another json file with following content{"b1":"b1val","b2":"b2val"}I want to shove the json object from file 2...
View ArticleDoes jq map function change the input object?
The docs certainly make it sound like it does not. But, I can't think of any way to explain the behavior below. What am I doing wrong?On some cluster data, I am trying to show the total number of cpus...
View Articlepass arguments to jq when inserting key not interpolated
When I runjq --arg md "blablabla" '. +={'content': "$md"}' blog.jsonin blog.json{"foo": "bar"}I get{"foo": "bar","content": "$md"}The desired output would be:{"foo": "bar","content": "blablabla"}
View Articlejq doesn't return non-zero for empty input
I have this line of code that works as expected:echo '{"slot":"we"}' | jq -re '.slot' || exit 1however this code doesn't raise an error even though I would expect so:echo '' | jq -re '.slot' || exit...
View Article