Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [jq]

Questions about the command line JSON processing tool jq.

3
votes
1answer
398 views

if else in jq is not giving expected output

I need to display users if their realm is internal. Input: [ { "name": "A_A", "uri": "https:test/test", "realm": "internal" }, { "name": "B_B", "uri": "https:test/test", ...
0
votes
2answers
21 views

How can I jq a line from a file from a remote server?

I would like to check a particular line from a remote server. So far, I can check if the file exists or not. But can I index a particular line using tool like jq? if ssh -q -i $pathToPem $...
-2
votes
0answers
29 views

Remove a part of json text in a file

I have a requirement need to delete part of json in a file using shell script, below is the content of the file need to remove post section pipeline { agent { docker { image 'java' }...
0
votes
3answers
69 views

jq is not appending json file

I have a json file like this: { "active": "secure", "secure": { "nodetype": "secure", "nodeid": null, "servers": [ "ts2.na", "ts1.na", "ts3.na" ], "stakeaddr": null, "email": ...
0
votes
1answer
44 views

How to get value with JQ (JSON) [closed]

I want to get the value of result.data (but it gives me null) can somebody explain me how targeting in the json below works. Do not understand it. { "ActTime" : 1547809207, "AstrTwilightEnd" : "...
0
votes
1answer
39 views

Need to associate one field with another in event, using bash script

I've gotten most of what I need done, but am stuck at the last part. I need to download the campaign from this month, but the url is associated w/ a campaign id and not the month (makes sense). I need ...
1
vote
3answers
102 views

How to extract a value from json response using shell script

{"expand":"renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations","id":"15114","self":"https://brg-jira-tst.state.mi.us/rest/api/2/issue/15114","key":"BRGTEST-11","fields":...
3
votes
2answers
99 views

parse JSON and malipulate its object values

I have a json file named xyz.json as follows [ { "annotations": [ "a" , "b" , "c" ], "class": "image", "filename": "vc00_02201.png" }, { "annotations": [], ...
1
vote
1answer
172 views

jq get attribute of nested object

I have the following structure (full file example here): { { "weather": [ { "advertiser": "Worldwide Forecasts", "notificationText": "Weather - Check the Weather Now - ...
1
vote
1answer
37 views

jq parsing json out of json values

I have something like the following echo "{\"t\":\"set foo='{\\\"mode\\\":1}'\"}"|jq . { "t": "set foo='{\"mode\":1}'" } and I'd like the output to look something like { "t": "set foo='{\"mode\"...
1
vote
1answer
173 views

Variable inside a curl Array [duplicate]

How to put the variable "user" in this array. The way it is not it doesn't work sadly. The $user variable should be john.smith for example. I have the following output: curl --header "Authorization: ...
3
votes
3answers
270 views

how to parse specific values from multiple JSON objects into csv using jq

I have following json [ { "ip":"105.105.105.105", "timestamp":"1543746097", "ports":[ { "port":80, "proto":"tcp", "status":"open", ...
0
votes
1answer
45 views

Slicing JSON with JQ to Create Arrays for New Relic Ingestion

I need to take some JSON, slice it using JQ so New Relic can parse it properly as it only takes a specific format when pushing JSON to their dashboards. I am using a bash script and WPCLI and then ...
-1
votes
2answers
112 views

jq: colorize selected field of json file [closed]

Extend of this question: jq: parse json file with constraint from other field After select "name" field I'd like to colorize it: { "checksum": "9e44bb7b76d8c39c45420dd2158a4521", "roots": { ...
0
votes
1answer
36 views

jq: parse json file with constraint from other field [duplicate]

Extend of this question: How to combine strings from JSON values, keeping only part of the string? Above link's output also include the "name" of folder type, need to exclude these "type": ...
1
vote
2answers
48 views

JQ (GET ID based on NAME)

I get a long list of such arrays { "id": "byu6g6c4cjys5mdkg5znh8ju8c", "create_at": 1511875272294, "update_at": 1511875272294, "delete_at": 0, "display_name": "BMA", "name": "...
0
votes
1answer
59 views

Json transformation using jq

I want to transform json to new line delimited json. I was attempting to do it multiple times using jq in bash, but I have not been able to get even close to the final output. INPUT: { "...
1
vote
2answers
359 views

Get values for a given key and its parent with jq

I've got a JSON array like so: { "1": { "available_memory": 1086419656.0, "available_memory_no_overbooking": 1086419656.0, "conns": 1.0 }, "2": { "available_memory": 108641236.0,...
0
votes
1answer
60 views

Dynamic options on whiptail got not printed

I have a json file which provides options for a 'whiptail' checkbox or radiolist. I grab them, make some redactions and wanna use them to show as options: defaults.json file: {"displays": [ {"...
0
votes
4answers
184 views

Strip newline characters and quotes from JSON array and set specific strings as variables via bash

I have the following JSON data: { "Name": "No.reply", "Email": "no.reply@xxxxxx.com", "ID": 5930, "details": { "message": "Your name: john doe\nEmail: johndoe@xxxxxxx.com\...
4
votes
5answers
2k views

looping through JSON array in shell script

Below is the curl command output (file information about branch), need script or command to print file name, filetype and size. I have tried with jq but was able fetch single value ( jq '.values[]....
0
votes
1answer
538 views

How to merge json files using jq or any tool?

Modifying the question to be more specific. There will be 2 JSON files where first one will have few blocks. And second one will have few blocks with few addition of redirection rules as you can see "...
5
votes
3answers
1k views

How to find and replace multiple field values using jq?

In the following json file, { "email": "xxx", "pass": "yyy", "contact": [ { "id": 111, "name": "AAA" } ], "lname": "YYY", "name": "AAA", "group": [ { "...
0
votes
2answers
71 views

How to parse json data using jq?

I need to fetch below objects from json which I am getting via API. I am trying with jq which is available on ubuntu 16.04. I am trying to get data in this format device_name C:| free 18707755008.0 ...
0
votes
2answers
78 views

How to swap two fields inside a JSON file

I have a file like this {"100":["0.00001","10","0.01"], "101":["0.0001","100","0.1"], "102":["1","1000","1"], .... "103":["0.01","10000","10"]} I want to swap the second number with the third, ...
0
votes
4answers
71 views

jq and awk for version file extraction

Using a JSON file with the following content: {"major":a, "minor":b, "hotfix":c} I'm trying to use jq to generate the following output: a.b.c I've used individual jq commands, such as jq .major ...
0
votes
1answer
27 views

JQ command to retrieve just the titles

I have this json file: "[{\"id\":188457,\"title\":\"Painted Dragon Tea Mug with Lid\",\"slug\":\"painted-dragon-tea-mug-with-lid\",\"image\":\"https:\\\/\\\/thievemedia.imgix.net\\\/2018\\\/09\\\/...
1
vote
1answer
343 views

Process JSON, containing new lines, with JQ and bash [closed]

I receive a JSON with a curl call similar to the following: output="$(curl -s "$api_url")" This output is in the JSON format and has to be processed by jq, it looks like the following: { "test":...
1
vote
1answer
259 views

jq print value of an element where a key array is empty or a key is missing

{ "vehicle": [ { "type": "car", "features": [ { "airbags": "yes", "engine": [ { ...
3
votes
2answers
3k views

jq - add objects from file into json array

I want to add an array with elements and value into an existing json file using jq. I already have a file (input.json) with { "id": 9, "version": 0, "lastUpdTs": 1532371267968, "name": "...
0
votes
0answers
150 views

How to join 2 json files by one key

jsonfile1 [ [ "i-pfasdqaertcbidlkl", "Some_Task", "t2.small", "running", "4.3.2.1", "Malaysia_db", "2018-04-10T13:56:50.000Z", "db",...
0
votes
1answer
70 views

jq + capture the tag value

is it possible to capture the required tag value by jq for example we want to capture the tag value - version1531837630468 while the input is ams-env so jq will capture the tag value by ams-env { ...
3
votes
1answer
239 views

Extract .json from a text file with arbitrary text

I have an output from a program that give some arbitrary text, with .json stuff inside like: blablablabla blablab some more text blablablabla blablab some more text { "glossary": { "...
0
votes
1answer
1k views

jq + how to print only the value of key under properties

we have the follwing json file more t.json { "href" : "htr", "items" : [ { "href" : "lpo", "tag" : "version1533203561827110", "type" : "kafka-log4j", "version" : 6, ...
0
votes
2answers
65 views

Why are spaces echoing as newlines?

I've got this JSON data that looks like this: [ { "loginId": "7638749", "customerprofileDetails": { "securityQuestions": [ "What is your favorite sports team?", "What ...
3
votes
1answer
446 views

Split a json array to multiple files

I have a file that looks like this: [ { "billingAccountNumber": "x", "paymentResponseObject": { "uiErrorDipslayMessage": "", "transactionStatus": "S", "...
1
vote
3answers
37 views

Rename a group of files to a string that exists inside each one

I have a group of json files. Each file contains one json object and they all have the same schema. There is a field in the json that I want to rename the file to. How can I do that? I came up ...
1
vote
2answers
296 views

Merging four new line delimited json files using jq

I am trying to merge 4 JSON files (in the future maybe two more). The only common factor between the newline delimited JSON files is "vulnid". File 1: {"vulnid":"cve1", "product":"product1"} {"...
0
votes
1answer
2k views

Export JSON to CSV with Headers using JQ

I have a (dictionary?) JSON file, similar to: { "Salad": { "name": "Dressing", "good": true, "status": true }, "Data_XML": { "name": "XML", "good": false }, "...
1
vote
1answer
229 views

Variable in curl adds backslashes to string

I am trying to use curl based on some variables to create customers in Stripe, but when I assign the token to a variable it is giving me an error on Stripe saying that it does not exist. However, if I ...
1
vote
1answer
38 views

replace tab with space

input json: [ { "name": "cust1", "grp": [ { "id": "46", "name": "BA2" }, { "id": "36", "name": "GA1" }, { "id": "47", ...
0
votes
1answer
186 views

jq - convert milliseconds

input json: { "id": "3885", "login": "050111", "lastLoginTime": 1529730115000, "lastLoginFrom": "192.168.66.230" } { "id": "3898", "login": "050112", "lastLoginTime": null, "...
1
vote
2answers
2k views

jq - print values in one line

json input: [ { "name": "cust1", "grp": [ { "id": "46", "name": "BA2" }, { "id": "36", "name": "GA1" }, { "id": "47", ...
3
votes
1answer
1k views

jq - print “-” for null values

input json: { "id": "3885", "login": "050111", "lastLoginTime": 1529730115000, "lastLoginFrom": "192.168.66.230" } { "id": "3898", "login": "050112", "lastLoginTime": null, "...
0
votes
1answer
202 views

Interpolate within single quotes

I have the following: COMMENT="A random comment" TEXT_JSON='{"person" : "Jim","comment" : "$COMMENT"}' echo "$TEXT_JSON" | jq . This prints { "person": "Jim", "comment": "$...
2
votes
1answer
262 views

jq + print properties from json file without removing the necessary backslash

we have the following json file: more file.json { "href" : "http://master02:8080/api/v1/clusters/HDP/configurations?type=kafka-env&tag=version1527250007610", "items" : [ { "href" : ...
10
votes
5answers
2k views

awk/sed/perl one liner + how to print only the properties lines from json file

how to print only the properties lines from json file example of json file { "href" : "http://master02:8080/api/v1/clusters/HDP/configurations?type=kafka-env&tag=version1527250007610", "...
0
votes
2answers
580 views

Accessing jq arrays with bash attribute

Is it possible to access json array with bash attributes? JSON example: { "data": [ { "id": 1, "name": "John" }, { "id": 2, "name": "Doe" }, .....
2
votes
0answers
175 views

process JSON format with JQ tools [closed]

I want check format keys in bash script. In my json if any keys match this format key[0-9][0-9]_$ my script exit 1 else exit 2. I want use JQ tools. Bash: #!/bin/bash json=$(cat <<EOF {"key11"...
0
votes
1answer
653 views

Check whether any value is zero using jq and return 0 to the calling shell script

I have this JSON file: { "key11":1010, "key12":12120, "key13":12103 } How can I use jq to check whether any of the values corresponding to a key[0-9][0-9] are zero, making jq exit ...