Questions tagged [jq]

Questions about the command line JSON processing tool jq.

Filter by
Sorted by
Tagged with
0 votes
1 answer
29 views

Jq substract 2 keys and add it to json

I have a json like this one { "status": "InProgress", "transactionId": "1652807586", "startTime": "2022-05-17T17:13:06Z", "...
user avatar
0 votes
2 answers
104 views
+100

Find number of lines between a pattern inside specific filetype

I have a notes.json file inside each directory. The following command counts length of each notes.json file and returns a sorted output by each file's number of lines. find . -name notes.json | xargs ...
user avatar
  • 7
1 vote
2 answers
62 views

How to merge arrays from multiple arrays in two JSON with JQ

I have two JSON files (file1.json and file2.json) with the following same structure as defined below with two array lists as shown below. The first file is (file1.json): { "Lists1": [ { ...
user avatar
  • 13
-1 votes
1 answer
31 views

Print json output to single line with comma separated

I am new to JQ, I have below json file [ { "userId" : "jens", "firstName" : "jens", "lastName" : "jens", "...
user avatar
  • 29
-1 votes
1 answer
33 views

Convert JSON to table, with headers of "Key" and "Value"

I have the following JSON output: [ { "enabled": "true", "policy_profile": "custom", "scan_local_files": "true", "...
user avatar
0 votes
1 answer
28 views

What's the shortest way of making jq read from a variable without using a pipe?

Let's say I have following bash script: json="$(curl -s "https://nominatim.openstreetmap.org/reverse.php?lat=-23.513442&lon=-46.384794&zoom=18&format=jsonv2")" jq '....
user avatar
  • 319
0 votes
2 answers
45 views

Is it possible to create JSON strings from a pipe using jq?

Let's say I use the command find "$HOME" -maxdepth 1 -type d and I get the following result: /home/user/folder1 /home/user/folder2 /home/user/folder3 /home/user/folder4 I'd like to use jq ...
user avatar
  • 319
-1 votes
1 answer
54 views

Use conditional formatting in jq - PowerShell [closed]

This is a follow up question from this question that got contributed by another person. I have following output from a webserver: { "status":"OK", "result":{ ...
user avatar
  • 1
0 votes
1 answer
41 views

Use conditional formatting in jq

This is a follow up to this question asked by me a few days ago. Say I have this output from a webserver {"status":"OK","result":{"string1":{"variable"...
user avatar
  • 3
1 vote
1 answer
127 views

jq: pass space-divided string as value

I'm trying to create new key-pair in existing JSON file where both key and value are sent as variables. I have the one-line command: jq --arg key "$key" --arg value "$value" '...
user avatar
-3 votes
1 answer
119 views

fillter json data with jq and print count of occurrences

im trying to fillter below json data with jq and expect ouput as below { "data": [ { "topic_name": "BookShow", "topic_id": "ABCDFG", ...
user avatar
  • 35
1 vote
0 answers
35 views

Basic webserver supporting post+get (using curl and netcat)

Sorry if the question's title isn't clear about the objective of this question. I was able to make a respond-only webserver using Bash only; when it gets a curl post request, it returns results no ...
user avatar
0 votes
1 answer
102 views

Getting the first/last/nth result from a jq select result

I am trying to find a way to pipe the result of my current script into another command which will leave me with just the last result of the array I get in my select here: jq -r --arg name "$1&...
user avatar
  • 1
0 votes
1 answer
298 views

filter array of objects using jq from json

im trying to fillter the below json data with jq and expected out-put as last. cat data.json { "params": { "filters": {}, "group_by": [ &...
user avatar
  • 35
0 votes
1 answer
35 views

Using jq, etract fields and subfields from list of objects, grouping paired subfields for saving to csv

With this data: [ { "c": "A", "e": "B", "score": 0.99, "v": [ { "context": "asdf", ...
user avatar
  • 1
0 votes
1 answer
623 views

Get value of JSON [] array in jq

How do you get the value of inside of an [key,value] array from a json output with jq [[1645128660000,0],[1645128720000,0],[1645128780000,0],[1645128840000,0],[1645128900000,0],[1645128960000,0],[...
user avatar
0 votes
1 answer
468 views

How to make jq output into a variable

here is my code curl random args "link" | jq and gives it gives is { "id": "961438154596153411", "username": "testing", "avatar": &...
user avatar
1 vote
1 answer
144 views

reformat json using jq

I have the below JSON file: { data : [ { "name" : "name1" "date" : [ { "date1" : "aaa", "date2" : "bbb" ...
user avatar
  • 13
0 votes
1 answer
406 views

jq - pipe multiple files from "find" to jq

I try to get all versions of a specific node-package within a project nodes_module folder. There are multiple package.json files and I wish to "grep" the ones under "dependencies": ...
user avatar
  • 3
1 vote
2 answers
403 views

Is there a way for 'jq' to read json with single quotes instead of double?

I use jq as an efficient way to parse out large nested json files. I sometimes want to us jq with a json formatted file which has single quotes instead of double around keys and values like below: { ...
user avatar
-2 votes
1 answer
56 views

how to txt -> json convert?

C-11^Mark^Docking AWS C-12^Mark^Docking AWS C-13^Lay^Ploting C-14^Lay^Ploting C-15^Lay^Ploting C-16^Vincent^GPU Calc C-17^Vincent^GPU Calc C-18^Vincent^GPU Calc C-19^Vincent^GPU Calc I use this ...
user avatar
2 votes
1 answer
83 views

Changing text into JSON

Example of input data (^-delimited fields): C-11^Mark^Docking AWS C-12^Mark^Docking AWS C-13^Lay^Ploting C-14^Lay^Ploting C-15^Lay^Ploting C-16^Vincent^GPU Calc C-17^Vincent^GPU Calc C-18^Vincent^GPU ...
user avatar
2 votes
2 answers
1k views

Unix shell quoting issues error in jq command

I'm trying out this command jq -n --arg KEY 'no leading zero' --arg VAL '.13452' '.+={$KEY:$VAL}' on bash terminal to produce output {"no leading zero":".13452"}. But I get the ...
user avatar
  • 237
2 votes
2 answers
205 views

append a json block before specific line using jq

I have a scenario where I already have a json file which I want to open and edit using jq. json file(temp.json) : { "a":{ "keya" : "abc", "keyb" : &...
user avatar
  • 85
0 votes
3 answers
146 views

How to get the json data used in each curl statement while using xargs and maps it to its corresponding result?

I have text file that has arguments of curl command. This is how the file looks 'https://example.com/tl/' -X POST -H 'Content-Type: application/json' --data-raw '{"email":"username2&...
user avatar
  • 119
1 vote
2 answers
1k views

JSON with jq into bash array / loop through

I have a JSON result which I want to go through and send an alert, if one or several of the values in the JSON string is smashing thresholds. This bash command: for sat in `docker exec -i storagenode ...
user avatar
  • 35
0 votes
1 answer
165 views

sway get the layout of the currently focused container

How do I get the layout of the currently focused container in sway (eg. 'splith', 'tabbed')? I guess the best way would be to parse the JSON output (sample below) of swaymsg -t get_tree using jq, but ...
user avatar
0 votes
4 answers
1k views

Using JQ to parse JSON string with multi-word values into an associative array

I am using bash with jq to parse data returned from https://ipinfo.io/json into an associative array. I found a nice example that almost does the job @ https://gist.github.com/awesome/...
user avatar
  • 167
0 votes
0 answers
77 views

Using jq to slice up a very large json file based on a particular associative key

Suppose I have a very large json file with millions of entries that have these keys (and many others) { "name": "assets/fUCcxWczWT0", "displayName": &...
user avatar
  • 99
0 votes
1 answer
480 views

Use jq to update property of object that contains other property with specific value

Using jq, is it possible to update values of an object with a specific value is some other property? In the example below I'd like to set the value of the "value" property of all objects ...
user avatar
1 vote
1 answer
250 views

Correct escaping of wildcard when using jq

The command below works: $ echo '{ "a": [ { "b": "1" }, { "b": "2" } ] }' | jq -r '.a[0].b' 1 But if I try to get the values of all the b elements ...
user avatar
  • 1,151
1 vote
3 answers
550 views

How do I get output using jq in the way it gives me the whole line where a word or string came in

My question is somewhat similar to it but still allow me to elaborate. I have been accessing a weather application called wttr.in from where I can get weather information. This can be easily called by ...
user avatar
  • 10.7k
0 votes
2 answers
357 views

Adding object string to array using jq doesn't translate escape characters

I'm trying to add an object {...} to parent [...] using jq. But the following parent="[]" block=$(cat << EOF { "block_id": "$block_id", "...
user avatar
  • 237
-1 votes
2 answers
56 views

building a json from jq

I want to generate a json file in jq like this below : { "cpe": "dabb8fbd-d7be-4175-abb4-c628bb8cf1b5", "ps": [ "Obev" ], "ets": 5, "pMap&...
user avatar
  • 17
1 vote
4 answers
2k views

creating a nested json file from variables using jq

I have a script where I am storing variables and using that I am trying to create a json output to a file. here is my json build format #!/bin/bash JSON_STRING=$(jq -n \ --arg ...
user avatar
  • 17
1 vote
1 answer
196 views

Defining functions and using map in jq

Can you explain to me how the following two differ? jq ´def addvalue(f): . + [f]; map(addvalue(.[0]))´ [[1,2],[10,20]] => [[1,2,1], [10,20,10]] jq ´def addvalue(f): f as $x | map(. + $x); ...
user avatar
  • 237
0 votes
1 answer
114 views

Parse lsblk with jq

I am currently trying to parse the output of lsblk with jq and filters it based on some criteria. Given the following example output: { "blockdevices": [ { "name":...
user avatar
  • 83
0 votes
2 answers
85 views

Fetch partial data from JSON Format data by jq

I have a sample JSON format data [ { "info":{ "disk_num":"2", "hostname":"hostA", "net":[ "eth0&...
user avatar
3 votes
1 answer
981 views

jq - set a value to another value conditionally

I need to set the value of a field in a json doc to one of three values using jq, depending on which exists. Notionally this looks like: set X to (if A exists, else if B exists, else if C exists, else ...
user avatar
  • 165
0 votes
2 answers
87 views

jq - assert exactly 1 element reutrned

I use the following jq snippet to extract a key out of an array of values: jq '[.[].refreshToken | select(. != null)] | unique]' How can I assert that only 1 element was returned? If more than 1 ...
user avatar
0 votes
1 answer
148 views

git clone repos with xargs and jq to a subfolder with the name of .owner.login (part of .full_name)

Goal Clone repos into subdirectories named .owner.login (argument in Github's REST API) with jq, git clone, and xargs. Preface I took a code somewhere that allowed me to clone repos with jq, git ...
user avatar
  • 103
0 votes
1 answer
462 views

How can I get jq to produce the array of values of a json dictionary?

I have a json dictionary $ cat foo.json { "black": "#073642", "red": "#DC322F", "green": "#859900", "yellow": "#...
user avatar
4 votes
1 answer
230 views

How to select based on an allowlist/blocklist using jq

Using jq, how can we select json elements from an array based on inclusion/exclusion of each element's key in some allowlist/blocklist? I want to do a case-insensitive contains (so allowlist/blocklist ...
user avatar
1 vote
2 answers
2k views

How to search and replace multiple values in an array using jq?

In the following json file, { "contacts": [ { "name": "John", "phone": "1234" }, { &...
user avatar
1 vote
1 answer
159 views

How may I convert this JSON into CSV?

I have below JSON document to convert into CSV. I need to iterate over the first column with the 2nd and 3rd (they can be either string or array) at the same time as one iteration. Example document: [ ...
user avatar
0 votes
1 answer
158 views

Parsing JSON with JQ using numerical key

I have a below curl which passes the value 2000 in the jq command which returns the right value... curl -X GET \ -H 'vmware-api-session-id: <auth-id>' \ -k -s 'https://<url>/api/...
user avatar
  • 1
8 votes
2 answers
3k views

how to jq nested array without key (only value) and convert to csv

I hope someone can guide me how do I convert below json to csv that I'm expecting for. Much appreciated in advance. Update: thanks for the solutions provided, but I found that sometimes array does not ...
user avatar
5 votes
2 answers
5k views

How to replace a value in json file using jq and returning the whole content

I have a json like this { "AgentGroupId": null, "AgentId": null, "CreateType": "Website", "IsPrimary": true, "IsShared": true, &...
user avatar
  • 155
0 votes
4 answers
1k views

how i parse following json array format. i want this filename value in bash or groovy?

How do I parse the following json array format? I want the filename value filewhichisdeploy in bash or groovy { "filewhichisdeploy":[ { "filename": "value" ...
user avatar
3 votes
2 answers
2k views

jq merge values of same key into an array?

I have a SQL resultset exported as JSON, in the form of 1:1 mappings in an array. e.g. [ { "subject": "Accounting", "level": "A Level" }, { &...
user avatar

1
2 3 4 5 6