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.

0
votes
0answers
25 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
41 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
24 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
43 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
350 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
53 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
41 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
126 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
40 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
1answer
103 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
25 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
291 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
537 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
429 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
64 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": "...
6
votes
1answer
742 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
475 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' ...
9
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
156 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
689 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
50 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
151 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
94 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
43 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
2k 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
642 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
788 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
148 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
412 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
629 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
89 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
311 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
159 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
188 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
67 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
1k 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
131 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
625 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\...
5
votes
5answers
5k 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
2k 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 "...
7
votes
3answers
3k 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
110 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
105 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
134 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
35 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
1k 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
598 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": [ { ...
5
votes
2answers
7k 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
184 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
107 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 { ...