Questions tagged [jq]

Questions about the command line JSON processing tool jq.

Filter by
Sorted by
Tagged with
0
votes
0answers
196 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
112 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
438 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": { "...
1
vote
1answer
4k 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
290 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
873 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
40 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
479 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
3k 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
299 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
73 views

replace tab with space

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

jq - convert milliseconds

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

jq - print values in one line

json input: [ { "name": "cust1", "grp": [ { "id": "46", "name": "BA2" }, { "id": "36", "name": "GA1" }, { "id": "47", ...
6
votes
1answer
3k 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
384 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
405 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
959 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
232 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
2k 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 ...
4
votes
1answer
3k 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 ...
3
votes
1answer
3k 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
2k 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 ...
12
votes
2answers
2k 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 ...
0
votes
2answers
9k 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": "...
0
votes
4answers
542 views

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

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
1k views

jq filter: show whole structure with selection

I have following file1 json: { "name": "eye", "attributes": [ { "name": "Width", "value": "1920" }, { "name": "Height", "value": "1080" }, { "...
4
votes
1answer
7k views

Convert JSON to CSV [closed]

JSON file: "UserDetailList": [ { "UserName": "citrix-xendesktop-ec2-provisioning", "GroupList": [], "CreateDate": "2017-11-07T14:20:14Z", "UserId": "1234556", "Path": "/", "...
1
vote
2answers
702 views

Using jq to get a structured output

I have the following json as my input for jq processing [ { "Category": "Disk Partition Details", "Filesystem": "udev", "Size": "3.9G", "Used": 0, "Avail":...
2
votes
3answers
818 views

Extract json array element based on a subelement value

We have the following example file ( very long file , this is short example ) "request_status" : "FAILED" { "href" : "http://localhost:8080/api/v1/clusters/sys41/requests/333", "Requests" : { ...
0
votes
2answers
253 views

How to convert e-05 to 0.0000

When I trying to parse html via curl+jq I see that where it see 0.0000123 it printing for example 1.23e-05.How can I convert this? Or if is so hard please write some sed or awk alternatives.
0
votes
2answers
601 views

replacing values conditionally, adding comment

the jq prints csv as in: ... | [.name, .userId, .groupId] | @csv' what does print: "nodea","0","6" "nodeb","1","0" how could I process it to get "n/a" instead of 0, and for >0 values appropriate ...
1
vote
1answer
215 views

get name values basing on a value of another attribute in the block

with jq, I'd like to get "name" value of blocks where "Media" attribute (under .session.attributeList) contains "node7000" string (in example json first array block matches it - there are two matching:...
20
votes
2answers
11k views

How to convert embedded (quoted) json string to json

I'm familiar with "jq" for parsing json. I work with one service that produces a json response where one of the properties is itself a json string. How do I convert that quoted value to a valid json ...
10
votes
3answers
16k views

JSON array to bash variables using jq

I've got a JSON array like so: { "SITE_DATA": { "URL": "example.com", "AUTHOR": "John Doe", "CREATED": "10/22/2017" } } I'm looking to iterate over this array using jq so I can set ...
3
votes
1answer
13k views

jq print key and value for all in sub-object

I found this Q/A with the solution to print all the keys in an object: jq -r 'keys[] as $k | "\($k), \(.[$k] | .ip)"' In my case I want to perform the above but on a sub-object: jq -r '....
1
vote
1answer
6k views

jq add or update a value with multiple --arg

I have file.json in the structure of: { "connections": {} } I want to update the connections object with variables $1 and $2. I'm trying: jq --arg ssid "$1" --arg pass "$2" '.connections.$ssid = "...
1
vote
1answer
3k views

Using multiple wildcards in jq to select objects in a JSON file

I have a JSON file with thousands of records line by line in the following structure, with different values. Example: {"in": 5,"li": [{"st": 1508584161,"abc": 128416626,"ta": 33888}],"usr": {"is": "...
3
votes
2answers
1k views

How to replace multiple lines with “sed” and convert to JSON?

{ "auth": 'log', "appid": 21, "custid": "599c1f910f53ada8468b4567", "hwid": "59e719ba0f53adfd6a8b4597" } 24/10/2017 12:44:24 -------------------------------------------------------------------...
1
vote
1answer
2k views

Parsing JSON with JQ

I'm using Bash to run the following script snippet on a Linux box. JSON file contents: [ { "id": 123456, "firstName": "John", "lastName": "Smith", "email": "user@domain.com" } ] The JSON file is ...
5
votes
5answers
708 views

parse colon separated value pairs

I've written a script that converts nmcli --mode multiline dev wifi into json but I'm finding it's inconsistent (breaks when results have a space), long, and hard to read. I'm wondering if it is ...
2
votes
3answers
945 views

How do I invoke jq inside awk?

Essentially I have a file.log as follow blah blah blah blah Hello world | {"foo": "bar"} blah blah Hello earth | {"foo1": "bar1"} Now my goal is to write some shell commands to have desire output ...
-3
votes
2answers
135 views

how to capture the properties tag from json file [duplicate]

this is very short list of my json file: "slider-client" : { "properties_attributes" : { }, "properties" : { } } }, { "spark2-hive-site-override" : { "properties_attributes" : { }, ...
2
votes
2answers
924 views

Use JQ to generate CSV from knife search

JQ looks like a great tool, but I'm struggling with it. Here is what I am trying to do: Extract just the values from this chef knife search and generate a CSV. given this command and output: knife ...
0
votes
1answer
90 views

Should I include code to install the packages that my script requires?

I have a script built just a way to learn bash and it uses jq for json parsing suppose someone else downloads it and runs the file, will bash automatically prompt the user to install jq or should I ...
5
votes
1answer
997 views

jq returning full result after operation

I'm adding a property to a JSON string with result=$(jq -c ".docs[$docIndex] + { \"value\": \"value\" }"<<<"$fileContent") Where the JSON inside $fileContent is { "docs": [ { ...
3
votes
1answer
554 views

bash string concatenation failed

Important note: I'm using Cygwin to run this script. I got a json string by executing result=$(jq -c ".docs[$docIndex] + { \"_rev\": \"rev\" }"<<<"$fileContent") Here is the JSON I get: {"...
3
votes
1answer
5k views

bash add property using variable with jq

To add a property to a JSON text I manage to use result=$(jq -c '.docs[0] + { "value": "someValue" }'<<<"$fileContent") But if I want to replace "someValue" by a variable: result=$(jq -c '....
0
votes
1answer
872 views

equal comparison on jq variable

I have a bash script that run a curl request and output the status via jq. I get the status as expected but when I compare the status it's always returning "non-equal" value, even if the value is ...