Questions tagged [jq]

Questions about the command line JSON processing tool jq.

Filter by
Sorted by
Tagged with
0
votes
0answers
13 views

Sending jq with argjson via ssh

I'm trying to run jq command via ssh for this JSON: { "nodes": { "app": { "nodes": 1, "is_manager": true, "ip": [ "0.0.0.0" ], "cpus": 16, "memory": ...
1
vote
1answer
14 views

How to construct a JSON object from multi-word (space-separated) bash variables?

I have a small bash script that uses jq to construct a JSON object from user input. Unfortunately, I am unable to convince jq to accept a multi word variable as a value to one of its keys. Here is an ...
0
votes
0answers
39 views

Help parsing JSON stream into Python with BASH and jq

I'm decent when it comes to writing python code but BASH is fairly new to me and I'd like some guidance on picking a high level approach to achieving my goal of reading sensor data from a live ...
1
vote
1answer
49 views

JQ filtered data with included parent key

I have json with given content: elements.json { "Metals": { "AlkaliMetals": { "Lithium": { "MeltingPoint": "453", "BoilingPoint": "1615" }, "Sodium": { ...
1
vote
2answers
45 views

How to convert '\t' and '\n' in my json terminal output into something useful?

I've got some JSON logs from AWS that I'm looking to clean up. They look like this... { "ingestionTime": 1568961184459, "timestamp": 1568961184430, "message": "START ...
1
vote
1answer
34 views

Parsing JSON with jq to get firstname in below JSON

[ { "firstname": "Alexander", "lastname": "Smith", "middlename": "Johnson", "birthyear": 1918, "deathyear": 1955, "gender": "M", "city": "Madison", "state": "...
0
votes
2answers
67 views

Using jq to create comma separated list fields in JSON array

I am trying to use jq to join the values inside a JSON array into a single line comma separated list. (Without trailing comma) { "hardware": [ "abc", "def", "ghi" ] } To create "abc,...
0
votes
0answers
25 views

Jq1.5 Remove and replace object within a json

I have been able to add a json object - that is saved in a file named auth.json - into the Main.json file. Auth.json { "name": "Authorization", "description": "This parameter represents the ...
2
votes
3answers
36 views

Splitting a file into two variables for piping to one command

I have a JSON object. it has two fields; { href: string, filename: string }. I want to download a file from href, and set its name to $FILENAME.pdf. This happens in a loop How can I do that? ...
1
vote
1answer
29 views

jq - multiple if

input json file: [ { "id": "1e9b2215-9efd-67cc-9113-1e21c74f09d3", "login": "u0159", "name": "Pat ABC", "role": "User", "groups": null, "disabled": false, "lLoginTime": ...
0
votes
1answer
30 views

jq filter remove or replace tab from inside @tsv

Input json: [ { "id": "1e9b2215-9efd-67cc-9113-2b21c74f09d3", "login": "u0154", "name": "Roman ABC", "role": "User", "groups": [ { "id": "1e99833f-9876-65d0-9d24-...
1
vote
2answers
34 views

How to JOIN two JSONs in environment variables?

I have environment variable, which contains JSON text. I want to add some data to it with jq tool. I want to keep all old fields but add and/or overwrite new ones. The idea is the same as with adding ...
0
votes
0answers
67 views

“az vm list | jq” fails with “parse error”

I'm trying to pipe the output of a command to jq but I get a parse error. The command I try to execute is az vm list | jq. When I run az vm list I get a JSON array printed out: [ { ... } { ... } ] ...
1
vote
1answer
103 views

Handling null (empty array) while converting json to csv with jq?

When trying to convert json to csv, I get an error about null with the following jq query: printf "[]" | jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $...
2
votes
1answer
25 views

What is the difference between vertical pipe and juxtaposition in JQ?

My program returns JSON into stdout and it is an object with operations field, which contains a list of operations. Each operation contains fields including id fields, for example: { "operations":...
0
votes
0answers
277 views

parse error: Invalid string: control characters from U+0000 through U+001F must be escaped

I have a script execute.sh which receive a JSON with a curl call #!/bin/bash source getoutput.sh server="$1" cmd="$2" res=$(curl -sS http://$server -X PUT -H "Content-Type: application/json" -d "{ \...
0
votes
1answer
196 views

Broken pipe only in Jenkins

I have a script that works just fine locally. But when I run it in Jenkins, I get Error: writing output failed: Broken pipe. My question is how can I fix this to work in jenkins? Now for the context ...
0
votes
0answers
108 views

Add bash variable as JSON key and value into object

I have a JSON array of objects like so . [ { "id" : "tmp1387816934708382026", "owner" : "john", "x11-display" : ":5", "x11-authority" : "/run/user/john/dcv/tmp1387816934708382026....
0
votes
1answer
72 views

jq: building a filter for csv output

I have the below JSON file: { "result": [ { "hostid": "12607", "name": "love", "host": "loveyou", "status": "0", "groups": [ { "groupid": "47", "name": "Flower" }, { ...
6
votes
3answers
489 views

Trim trailing zeroes off a number extracted by jq

The following command achieve my goal by grepping BTC price from specific exchange. curl -sS https://api.binance.com/api/v1/ticker/price?symbol=BTCUSDT | jq -r '.price' the output will be for the ...
0
votes
1answer
304 views

Get parent nodes by child node selector with jq

I'm trying to parse json with jq { "xxx": { "aliases": { "business_event": { "is_write_index": true } }, "mappings": { "...
0
votes
1answer
69 views

Rename files based on JSON content using jq

I need to make a shell script that uses jq to rename below mp4 file(s). (could have use jasonpipe but didn't know how to install it on mac) File Dowloaded: title1-1000221327.mp4 title1-1000221327....
1
vote
1answer
356 views

Convert json file to a “key-path” with the resulting value at the end of each “key-path”

I have a large and relatively complex json configuration file that I want to search for keys and/or values using simple tools like "grep". When I 'grep' the file I would like to have in the output ...
2
votes
2answers
90 views

JQ Linux JSON Parse Unknown Key

I want to build an automated script which builds an new VPS Server on the page vultr.com. They also have an API Access and I could create it and receive also anything I need. The problem is, vultr ...
1
vote
2answers
926 views

Passing variable to jq to edit a json file

I am trying to pass a variable into jq like this '.Linux.date.$var' so far I have tried quoting them by name which is working fine. But I want to use variable to call them. I have this, which is ...
2
votes
1answer
45 views

Replace part of a vdf file

Again I am attempting to alter configuration file via script. I looked into jq but jq seems to support the .json format alone. .vdf is almost exactly like .json except that there are no commas. ...
1
vote
1answer
795 views

jq (command-line JSON processor) merge multiple JSON strings from STDIN

I am trying to merge two different JSON strings from STDIN (using pipe, not files) using jq command. Here's the command trying: curl ipinfo.io api.ipify.org/?format=json 2>/dev/null | jq -s ...
0
votes
1answer
1k views

parse JSON data using jq and convert into csv

I am downloading api json data and converting into my final result as a csv file. The sample data is in the below form: { "content": [{ "Title": "abc", "brand": "xyz", ...
1
vote
2answers
1k views

Loop into JSON Array in Bash Script

I make a curl request to an API and get a json return with jq. The result { "errors": [], "metadata": { "clientTransactionId": "", "serverTransactionId": "20190318164551347" }, "...
2
votes
0answers
102 views

JSON -> csv creating header line and padding header if found empty field

I have a programme in bash that get JSONline files with several million of these object per line (See source) { "company_number": "09626947", "data": { "address": { "address_line_1": "...
8
votes
1answer
2k views

Error message “Cannot index array with string 'Title'” when parsing JSON data with jq

{ "content": [ { "Title": "abc", "brand": "xyz", "size": "5 g", "date": "2019-01-01", "details": { "Temperature": [ { ...
0
votes
1answer
1k views

Linux Shell - How to remove escape characters generated by JQ when json is read with sed?

I am trying to read a json file and use its output in jq to build another json, combining so said json file and other values, and pass it to CURL I read the file with policies=$( sed 's/\\//g' ...
10
votes
4answers
2k views

Wrap all numerics in JSON with quotes

There are JSON data which contains some numeric values. How to convert all numerics to strings? (wrap with quotes) Example: { "id":1, "customer":"user", "plate":"BMT-216-A", ...
0
votes
2answers
309 views

append values under element in json

the following parameter include list values ( list of machines ) for example echo $list_of_machine worker01.sys645.com worker02.sys645.com worker03.sys645.com worker04.sys645.com worker05.sys645....
3
votes
1answer
1k 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
74 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 $...
0
votes
3answers
253 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
168 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
45 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
5k 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
1k 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
2k 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
199 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
701 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
1k 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
133 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
593 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
219 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
424 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
80 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: { "...