Questions tagged [jq]
Questions about the command line JSON processing tool jq.
368
questions
1
vote
1
answer
23
views
Convert csv out of json in new coloumn
The below is my json code
[
{
"kind": "user",
"version": "v2",
"metadata": {
"name": "person1"
},
"...
0
votes
1
answer
42
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&...
-1
votes
1
answer
46
views
Add Array of Object in JSON with condition
I have system that output multiple types of JSON file with data
Is there any chance to implement above three conditions using JQ package? I am exploring map, arg and argjson command. But I am having ...
2
votes
2
answers
146
views
Convert json to csv with headers in jq
Is it possible to convert this json:
[
{
"bytes": 276697,
"checked": false
},
{
"bytes": 276697,
"checked": false
...
0
votes
1
answer
47
views
jq not showing all the results
I have the following json:
[
{
"_source": {
"layers": {
"http2": {
"http2.stream": {
"http2.length": "...
8
votes
4
answers
785
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": "@...
0
votes
0
answers
51
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 ...
1
vote
1
answer
70
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": &...
0
votes
2
answers
135
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": "...
0
votes
2
answers
137
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",&...
1
vote
1
answer
455
views
How to keep one specific key from a nested json object?
I have the following config.json file:
{
"auths": {
"reg1.io": {
"auth": "...
1
vote
2
answers
183
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(...
7
votes
4
answers
692
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&...
0
votes
1
answer
149
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:...
5
votes
1
answer
487
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 ...
4
votes
4
answers
1k
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",
"...
1
vote
2
answers
988
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:...
0
votes
1
answer
415
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"...
2
votes
1
answer
3k
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 ...
1
vote
1
answer
171
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 ...
3
votes
2
answers
3k
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"...
4
votes
2
answers
4k
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 ...
5
votes
2
answers
3k
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 ...
-1
votes
1
answer
243
views
numbering to each jq output
I have a JSON file
{
"fieldA": {"fieldData": "XYZ"}
"fieldB": {"fieldData": "PQR"}
"fieldC": {"fieldData": ...
1
vote
2
answers
2k
views
get key and value from json in array with check
I had a json
[
{
"name": "type1",
"type": "string",
"values": {
"set1": "dataA1",
...
1
vote
2
answers
3k
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",...
0
votes
1
answer
167
views
Use Value of Json as a variable for x number of times
I have a json file with the ids of list for their entries
[
{
"list_id": 1,
"list_key": "gnfijgndngd458wjfisdnfpon",
"entries": 0
...
2
votes
2
answers
1k
views
How can I sort XML elements by their attributes?
How can I sort this XML?
first by alphabetical element: module before property.
then by the alphabetical name attribute: <module name="ClassTypeParameterName"/> before <module name=...
0
votes
1
answer
2k
views
jq: error (at input.json:45): Cannot index array with string "value"
I try to convert my .json files to .csv with jq. I'm getting cannot index array with string value on all my values. .json
{
"organic_data": [
{
"description": "...
1
vote
1
answer
360
views
is there a way to add keys to child clauses in jq
I want to add a value to a json text, but jq '.jq_path +{"key":"value"}' will only output that section and jq '. +{jq_path:{"key":"value"}}' will replace all ...
2
votes
2
answers
2k
views
How to parse and add content to json using bash?
I am following the ideas from the stackexchange articles below
here to select and delete an element Delete Element
here to append an element: Add New Element
but I am having problems with quotes ...
2
votes
1
answer
3k
views
Jq contains query with a variable containing spaces
I've been having an issue with searching a json field that has spaces it in it with a variable containing the search term that also has spaces in it. I've been using the contains search but I'm not ...
0
votes
1
answer
556
views
Parsing JSON output to variable in bash using jq filters
I have a query like this:
curl -s \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_TOKEN" \
--data "$(echo $PAYLOAD)" \
https://myapi/...
1
vote
1
answer
1k
views
jq select match pattern but not if preceded by other pattern
An application called "vagrant packer" always downloads the iso and checksum file from the remote location every time I run it, so I'm creating a script that downloads the iso to a local ...
0
votes
1
answer
4k
views
How to use jq to convert an bash array in command line to json array? [duplicate]
$ jq -c -n -e '[$x, $y]' --argjson x '"a"' --argjson y '"b"'
["a","b"]
I know that I could do something like the above. If I want to generate a json array from ...
2
votes
1
answer
362
views
Add Bash Variable as key for JSON object
I am running a command that is pulling json from kubectl and I need to take that json and input it into another json array.
Currently, my command looks like this
kubectl get ingress -o json | jq --arg ...
2
votes
0
answers
175
views
How to combine two JSON objects using jq
I have two files:
kube-apiserver.json
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
[...]
},
"spec": {
...
2
votes
1
answer
1k
views
How to merge multiple json object into one json array in shell
I have a requirement to read some fields of json data from a file to compose a new json list. The file is generated by reading data from multiple servers via pssh
# pssh_result.txt
[1] 14:44:51 [...
1
vote
1
answer
762
views
Getting null as result from JQ command only when using variable
I am trying to use jq to parse some JSON to allow me to get values out of a json file. The setup is I have a JSON file that if I run my jq command against with my manually entering the key it will ...
1
vote
1
answer
2k
views
How can I set the spacing option in jq?
I use jq to process json. It outputs pretty-json. How can I customize the amount of spaces when it reformat the file?
0
votes
2
answers
1k
views
How to use jq for parsing JSON as env vars
I have the following json structure
[{"name":"SQS_URL","value":"xyz"}]
I would like to convert it to this structure
SQS_URL=XZY
0
votes
1
answer
3k
views
Curl command with jq
learning the curl command first time, I am using this jason
{
"count": 32,
"results": [
{
"@class": "SFTPServer",
"enabled": true,
...
1
vote
1
answer
219
views
Sum up entries from json and save it in a variable
I have the below json file
[
{
"n_id": 1,
"n_key": "sdfvnifughsdfvnsdfvnsd",
"entries": 7
},
{
"n_id": 2,
...
1
vote
1
answer
399
views
Parse a multidimensional json array using bash
I'd like to iterate over a multidimensional json array in bash but haven't found a solution.
Here is what the multidimensional array would look like:
{
"FILES": [
[ "file1....
0
votes
1
answer
3k
views
How to dynamically find a value of a key-value in json in bash script
I'm new to bash scripting. I am iterating over a list and want to get the value from a JSON object. I've tried all 3 of these and am getting a jq: 1 compile error
What is the proper syntax?
for key in ...
1
vote
1
answer
2k
views
jq nested reduce/grouping of JSON data
I'm working on a large JSON dataset (1GB+) and need to merge similar array objects, then merge their nested similar objects.
Starting with, I have rows such as:
[{"item": "item1", &...
0
votes
2
answers
599
views
Save a json value as variable
I am getting the below output from a command.
{
"data": {
"access-type": "ObjectRead",
"access-uri": "/p/u4yRbnS_Yv29ivICXNWz-...
2
votes
3
answers
2k
views
Can I use jq to prettify a file in place?
I've written a shell script to use jq to read a json file and write a pretty version of the file:
cat input.json | jq . > pretty.json
cp pretty.json ./input.json
rm pretty.json
Lines 2 and 3 were ...
2
votes
4
answers
396
views
Create a json from text+tsv file
I am total beginner
Never Made a JSon In my life
Only parsed a few json
Text File:
Number of Category may be varibale
Category1
1111|2222|3333|444|5555
6666|7777|8888|9999|1111
0000|1111|22222|3333|...
1
vote
2
answers
526
views
JSON PARSING: Conditional extract key, and if it's null, fallback to other key
I am a total beginner to JSON and to jq.
I have the following JSON document:
{
"initial": [
{
"HIGH": null,
"LOW": "XXX",
"LARGE&...