Skip to main content

Questions tagged [jq]

Questions about the command line JSON processing tool jq.

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

How to escape symbols in jq query?

I try to get area of JSON created by kubectl as another user. runuser -l username -c "kubectl get ing -A -o json | jq --arg namespace "default" -r '.items | map(select(.metadata....
Aleksey's user avatar
  • 25
-2 votes
2 answers
65 views

bash script replace credentials in json file

I have json file like this: { "sdpSemantics": "unified-plan", "iceServers": [ { "urls": "stun:1.1.1.1:3478" }, { "...
user613400's user avatar
5 votes
2 answers
254 views

Using jq to copy field from one object to a later object in a JSON array

I have a series of events represented in a JSON array. I want to move data in the fields of earlier events to a later event. Is there a way to do this with jq? Here is an example of what I'm looking ...
ralmond's user avatar
  • 51
4 votes
1 answer
146 views

Merging with JQ

I am looking to merge two different JSON files into one file - file 1 [ { "namespace": "lerjr-rb26-sandbox-keycloak", "name": "keycloak", "...
Victor Gonyo's user avatar
0 votes
1 answer
63 views

data json to env unix with jq

i have problem my command for me is working but the command export test=test not working in command with jq but if i run only export test=test it's working so i have file test.json inside : { "...
Mohamed N.'s user avatar
8 votes
1 answer
400 views

How to use jq to get a value from two possible paths?

I wanted to use jq to get a specific value b from two possible paths (and these two only). So, basically, I wanted to say jq '(path1 OR path2) | .b' which should work if b is at one of the two paths ...
tinlyx's user avatar
  • 830
0 votes
1 answer
47 views

Add \t to jq resulted array extraction

I want to add \t before each element in the resulting jq array and this is for formatting purposes as the result will get added to a file. here is the json file: { "array": ["...
kyles's user avatar
  • 33
3 votes
1 answer
421 views

jq skip iteration over null

I am using jq 1.7 Data I am operating on info.json downloaded by yt-dlp yt-dlp --write-info-json --skip-download https://www.youtube.com/watch?v=vlIO-7Rpi7c JQ - Task Now I want to remove all array ...
Porcupine's user avatar
  • 2,056
4 votes
2 answers
379 views

jq: Printing multiple values from multiple arrays at once

The default functionality of jq is to send each object from an array one at a time, though the join operator can merge those values. My problem is in trying to print all the values from multiple ...
T145's user avatar
  • 213
4 votes
2 answers
125 views

sort all arrays in a JSON file depth-first to get a consistent order

I'm tracking the configuration of some system in JSON format in a revision control system. Unfortunately that configuration is retrieved using some closed-source proprietary command, and the output ...
Stéphane Chazelas's user avatar
6 votes
2 answers
995 views

JQ returns json lines without commas

To be clear - I want a pseudo-JSON output that will be written into another static JSON file here... so not wrapped in an array or anything, simply getting the missing commas after each entity in my ...
Seer's user avatar
  • 165
0 votes
2 answers
112 views

Executing `yq`, but `jq` gets executed

I am very confused. I installed the Debian package yq But if I call it, jq gets executed: root@rescue ~ # echo '{"key": "value"}' | yq -p=json jq: Unknown option -p=json Use jq --...
guettli's user avatar
  • 1,449
1 vote
2 answers
125 views

pipe or redirect output from curl to ssh command

I'm pretty sure this isn't possible, but I have been wrong in the past. Basically, what I'd like to do is take the JSON output from a curl command and pipe it to jq for prettiness. Which works fine. ...
supradave's user avatar
4 votes
2 answers
711 views

Displaying "current" key in jq

I have a dictionary keyed on usernames, like: "userinfo": { "alice": { "key1": 1, "key2": 2}, "bob": { "key1": 11, "key2": 22}, ......
Chip Seraphine's user avatar
-2 votes
1 answer
115 views

Is there a simple way to store bash variables via jq?

I am seeking an easy way to create persistent bash associative array (dictionary) storage without using declare and its options to manually read and write associative arrays externally. 'jq' and 'json'...
Paul's user avatar
  • 210
1 vote
1 answer
112 views

How to parse a JSON document using jq when an array sometimes does not exist?

I have a utility that gives me JSON data with varying structure. Sometimes an array is missing, and some times it's not missing. For example, this is with the array missing: { "returned": ...
Miguel7799's user avatar
2 votes
1 answer
38 views

Transforming nested arrays in Office 365 logs into table

I want to release a simple tool based on jq to transform some common Office 365 Unified Audit Log events into a tabular report format, but having challenges with the way certain key arrays are nested. ...
whitepaws's user avatar
  • 121
1 vote
1 answer
58 views

jq expression to merge

I have the below JSON document from the Junos REST API. I am trying to simplify the document down to just a select few items. How would I accomplish this? Expected JSON: [ { "status": ....
verideskstar's user avatar
0 votes
1 answer
142 views

Search field and replace other in jq

I am trying to search for an object having a specific property and then update another property. Given this input: [ { "replacements": [ { "newValue": "0&...
Jazzschmidt's user avatar
2 votes
1 answer
206 views

How to pass a single value argument to a JSON file from a script without overriding the existing values?

I have the following JSON file named pool.json: { "AllocateActions": {}, "Available": true, "Description": "Pool for nodes in cluster - {{CLUSTER_NAME}}&...
aneeshdevcube's user avatar
5 votes
1 answer
1k views

How to convert timestamp value to number and then convert to human readable

I have a string timestamp key I need to convert to a number because strftime throws an error that it needs to be a number. journalctl -n1 --output=json | jq '.__REALTIME_TIMESTAMP | tonumber |= (. / ...
user avatar
1 vote
0 answers
43 views

Why can't I cat a file, pipe it to jq, and redirect the output to another file? [duplicate]

I want to use jq to pretty-print a JSON-format file, and pipe the result to another json file. My first instinct was cat foo.json | jq > bar.json but this results in an empty bar.json: $ cat <&...
StoneThrow's user avatar
  • 1,787
1 vote
1 answer
1k views

Add/modify key/value in json object

I've asked a similar question in the past but I'm having a hard time adapting that solution to this problem. I have the following json array: $ jq <<<"$json" [ { "id"...
jesse_b's user avatar
  • 37.6k
0 votes
3 answers
567 views

Don't split at spaces in jq output

I used jq to convert an array of words into an argument for a java program. its like arguments=$(jq '.nameField | "-i " + "\"" + . + "\""' file.json) java .... ...
decipher's user avatar
  • 312
1 vote
1 answer
37 views

Convert csv out of json in new coloumn

The below is my json code [ { "kind": "user", "version": "v2", "metadata": { "name": "person1" }, "...
code userit's user avatar
0 votes
1 answer
583 views

How do I refer to attributes with dollar signs in the name in jq?

I have some JSON: { "Data": { "$id": "1", "voters": { "$id": "2", "$values": [ { "$id&...
Joel Breazeale's user avatar
0 votes
1 answer
309 views

Conditional JSON transformation using jq

I have a system that outputs multiple types of JSON files with data. Is there any chance to implement the three conditions below using jq? I am exploring the map() command, and the --arg and --argjson ...
infotechsups's user avatar
2 votes
2 answers
3k views

Convert json to csv with headers in jq

Is it possible to convert this json: [ { "bytes": 276697, "checked": false }, { "bytes": 276697, "checked": false ...
Daniel Krajnik's user avatar
0 votes
1 answer
143 views

jq not showing all the results

I have the following json: [ { "_source": { "layers": { "http2": { "http2.stream": { "http2.length": "...
Manuel Rijo's user avatar
8 votes
4 answers
2k views

How to format a JSON string as a table using jq?

I need to convert a JSON string using jq, as shown below, into a table format for displaying the output in the terminal. { "results": [ [ { "field": "@...
Velin Budinov's user avatar
0 votes
0 answers
237 views

Looking to be able to do substitutions in JSON file using jq

I am looking to design a JQ function which would allow for management of substitution of data from within the JSON file itself along with shell environment substitutions (and shell function ...
Michael Klusman III's user avatar
1 vote
1 answer
247 views

From array of semver version numbers to an major/minor object hash in jq, even possible?

Input [ "8.1.1", "7.4.33", "7.4.5", "8.2.6" ] Ouput { "7": "7.4.33", "7.4": "7.4.33", "8": &...
gremo's user avatar
  • 167
0 votes
2 answers
435 views

Using jq to parse invalid JSON?

Can jq parse invalid JSON such as this?: [2023.06.07-21.58.47] StatManagerLog: { "RoundState": { "State": "Starting", "Timestamp": "...
swat37's user avatar
  • 3
0 votes
2 answers
343 views

Add new key to JSON file, with value equal to the length of other key's value

I'm adjusting a JSON file that holds a large number of objects. Here are the first three objects as an example: {"id":"0704.0001","submitter":"Pavel Nadolsky",&...
A.Co's user avatar
  • 3
1 vote
1 answer
1k views

How to keep one specific key from a nested json object?

I have the following config.json file: { "auths": { "reg1.io": { "auth": "...
Franck's user avatar
  • 13
1 vote
2 answers
319 views

How to parameterize a `jq` expression to return either a selection or its complement?

Let's assume I have two quite complex jq expressions, but that they only differ in that one returns the complement of the other, i.e., that the only difference between them is that one does select(...
Kusalananda's user avatar
  • 339k
7 votes
4 answers
2k views

How to gather values into array by keys?

Given input in entries format, possibly with duplicated keys, e.g. [ {"key": "a", "value": 0}, {"key": "a", "value": 1}, {"key&...
友人A's user avatar
  • 173
1 vote
1 answer
581 views

problem with piplining using jq [duplicate]

The exact question was asked here: Using jq within pipe chain produces no output but the answser provided there did not solve my problem. Also, I read the following: Turn off buffering in pipe https:...
xrfang's user avatar
  • 215
4 votes
1 answer
1k views

Merge JSON arrays on dissimilar keys

I have 2 JSON files with arrays (extracted from restAPI using curl in bash). Both files are arrays with a .result object at the top which needs to remain. The first has a .name field and many (over ...
BrandonH's user avatar
4 votes
4 answers
2k views

How can I edit this JSON file with bash script and jq

I have config.json file with the following content: [{ "host0": "11.11.11.11", "host1": "22.22.22.22", "host2": "33.33.33.33", "...
Trinitron's user avatar
0 votes
2 answers
4k views

How to print key and value with jq

I'm new to jq and trying to extract key and value from selected fields. { "StackEvents": [ { "StackId": "arn:aws:cloudformation:us-east-1:1234567890123:...
learner00's user avatar
0 votes
1 answer
841 views

Get parent of all matching value in JSON using jq

I am new to jq and I have a scenario to get the parent(at a particular level) of any matching value in the json file. Below is the sample data. { "DevOps": { "us-east-1"...
Murali SP's user avatar
5 votes
1 answer
10k views

jq - select an attribute based on a key that starts with or contains a string

input.json { "Stack": { "KeypairNameB651C0C1": "key-0123456abcdefg", "AsgNameA7D05B90": "my-asg-name" } } The key names could vary, but ...
tkwargs's user avatar
  • 153
1 vote
1 answer
411 views

Why are bash and git-bash results different?

Newbie trying to learn bash and jq. I'm on a Windows machine so I thought I'd test with git bash - I thought git bash was identical to bash running on Linux. For my test, I'm trying to extract a list ...
Henry Lee's user avatar
  • 119
6 votes
2 answers
8k views

get unique without sorting in jq

Array => ["cross", "base", "cross", "dunk"] I want to delete all repeated values without sorting. Command: jq '. | unique' file.json Output: ["base"...
decipher's user avatar
  • 312
4 votes
2 answers
8k views

Keep escaped forward slashes in JSON string values with jq

According to the JSON specification, forward slashes don't have to be escaped with a backslash but they can be. I have a JSON file which has all forward slashes in string values escaped for compatibly ...
YourMJK's user avatar
  • 151
6 votes
2 answers
6k views

How to add a key value pair into a JSON file with JQ?

I have the following JSON file located at /tmp/target.json: { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", ... } } I want to add ...
CaTx's user avatar
  • 171
-1 votes
1 answer
513 views

numbering to each jq output

I have a JSON file { "fieldA": {"fieldData": "XYZ"} "fieldB": {"fieldData": "PQR"} "fieldC": {"fieldData": ...
decipher's user avatar
  • 312
1 vote
2 answers
9k views

get key and value from json in array with check

I had a json [ { "name": "type1", "type": "string", "values": { "set1": "dataA1", ...
decipher's user avatar
  • 312
1 vote
2 answers
6k views

Create a Json using bash script

I have a file which has list of cidr's. How can I create a big json with below format using bash script With single CIDR [{"source":"1.1.1.0/32","protocol":"17",...
ph3ro's user avatar
  • 378

1
2 3 4 5
8