Quantcast
Channel: Active questions tagged jq - Stack Overflow
Browsing all 584 articles
Browse latest View live

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 Article


Image may be NSFW.
Clik here to view.

jq 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 Article


Select 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 Article

Delete 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 Article

How 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 Article


How 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 Article

Issue 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 Article

How 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 Article


jq - 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 Article


How 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 Article

Changing 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 Article

Exporting 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 Article

How 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 Article


JQ 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 Article

Filter 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 Article


jq 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 Article

Replace 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 Article


Does 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 Article

pass 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 Article

Image may be NSFW.
Clik here to view.

jq 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
Browsing all 584 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>