Stack Exchange Network

Stack Exchange network consists of 174 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.

1
vote
1answer
25 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\"...
0
votes
0answers
16 views

Add a Key Value Pair in JSON Object Using JQ and Bash

I have a script that crawls through a directory and pulls info from WP sites and builds a JSON array of objects that will eventually be fed into a visual dashboard. The script works perfectly but I ...
1
vote
1answer
29 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
2answers
68 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
21 views

Slicing JSON with JQ to Create Arrays for New Relic Ingestion

sorry for the long title. 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 ...
-1
votes
2answers
40 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
20 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
1answer
21 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
45 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: { "...
0
votes
1answer
40 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
37 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
116 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
4answers
646 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
118 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 "...
4
votes
2answers
478 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
51 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
73 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
29 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
25 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
140 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
120 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": [ { ...
2
votes
2answers
2k 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
125 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
56 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
83 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
319 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
47 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
325 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
36 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
232 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
1k 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
206 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
29 views

replace tab with space

input json: [ { "name": "cust1", "grp": [ { "id": "46", "name": "BA2" }, { "id": "36", "name": "GA1" }, { "id": "47", ...
0
votes
1answer
94 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
1k views

jq - print values in one line

json input: [ { "name": "cust1", "grp": [ { "id": "46", "name": "BA2" }, { "id": "36", "name": "GA1" }, { "id": "47", ...
1
vote
1answer
648 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
165 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
183 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" : ...
9
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
463 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
149 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
310 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 ...
1
vote
1answer
1k views

Match keys with regex in jq [closed]

I'm writing a script that analyses JSON input (jsonfile): { "key11":1010,"key11_yes":13,"key11_no":14, "key12":12120,"key12_yes":9,"key12_no":25, "key13":12103,"key13_yes":13,"key13_no":20 ...
1
vote
1answer
285 views

jq - select hostname starting from a string

input json: [ { "id": "89", "hostname": "abcd" }, { "id": "89", "hostname": "babcd" } ] How to modify below filter to get on output only hostname beginning with "abcd"? $ jq ...
0
votes
2answers
50 views

Add 100 to decimals in Multiple TXT files

I am confused over this, so need some help. I have multiple txt files in one folder. And there's some content in those text files. Now there is one text "moveLimit":30, (comma is after the decimal). ...
1
vote
2answers
338 views

Identify .json files with empty arrays?

I have a folder with multiple .json files. There are certain files with empty arrays, Sample file : { "WarehouseActivity": [] } The file has no other data apart from the one shown above. I need to ...
8
votes
2answers
1k views

Using jq within pipe chain produces no output

The issue of jq needing an explicit filter when the output is redirected is discussed all over the web. But I'm unable to redirect output if jq is part of a pipe chain, even when an explicit filter is ...
-1
votes
2answers
4k views

merging many json files into one

I have many json files of such format: sample file1: { "attributes": [ { "name": "Node", "value": "test" } ] } sample file2: { "attributes": [ { "name": "...
1
vote
4answers
320 views

parse colon separated value pairs, with escaped colon characters in field(s)

I'm trying to process output from nmcli command (colon separated values), but failing to handle / ignore escaped colons in MAC or BSSID. I've tried awk, jq, sed, regex but just not getting it... ...
0
votes
2answers
500 views

jq filter: show whole structure with selection

I have following file1 json: { "name": "eye", "attributes": [ { "name": "Width", "value": "1920" }, { "name": "Height", "value": "1080" }, { "...