Questions tagged [jq]

jq is a sed-like tool for JSON data – you can use it to slice, filter, map, and transform structured data with the same ease that sed, awk, grep and friends lets you play with text.

jq is a succinct programming language for querying and manipulating JSON data or plain text files. You can use it to slice, filter, map, and transform structured data with the same ease that sed, awk, grep and friends let you play with textual data. jq is stream-oriented and uses the pipe symbol | to connect filters familiarly.

Resources

6401 questions
2
votes
1 answer

jq json array mixed (duplicated) results

I have a JSON array, which I want to extract values from (using jq): This is a reduced example { "query": "", "results": [ { "id": 111, ... "buyer": { "email": "mail1@mail.com", ... "billing_info": { …
Germán
  • 328
  • 6
  • 15
2
votes
3 answers

How to use jq to extract variable keys and their values from JSON?

If I have a JSON file with variable key names like this: { "john": {"age": 40, "nickname": "jo"}, "mary": {"age": 50, "nickname": "mo"} } How do I use jq to extract the keys with some of their values? Example: Extract the names and their…
Markus
  • 1,635
  • 15
  • 17
2
votes
2 answers

How to replace double backslash in a JSON text?

I've got this json file: { "module": { "data": { "orderInfo_203759231000": { "fields": { "createdAt": "Dipesan pada\\r\\n 17 Mei 2018", "tradeOrderId": 203759231000 …
Joe
  • 791
  • 1
  • 9
  • 24
2
votes
2 answers

Pick up the latest releases from each major node version with jq

Are there any smart ways to pick up the latest releases from each major node version with jq? Or do I have to write another wrapper shell script to handle its output? What I want to get (there are three major versions: v8, v9 and v10) the latest…
Bill
  • 2,494
  • 5
  • 26
  • 61
2
votes
2 answers

flat CSV to nested JSON tree for D3.js

I have a lot of data in a CSV that I need to convert to nested JSON to use in a D3.js tree. Here's a sample of the CSV data: Domain,Subject,Section,Topic Networking,Networking Communications,Data Transmission,Data - Overview Networking,Networking…
FDRH
  • 209
  • 3
  • 11
2
votes
2 answers

Updating JSON object values dynamically and storing them in a new file in BASH

I am completely new (an intern with less than two weeks of hands-on experience) to BASH, JSON and jq. But I have been given a task to replace JSON object value from an array iteratively. I have managed to write the following code. I am trying to…
2
votes
1 answer

Using jq to convert JSON {"k1":"v1","k2":"v2"} into CSV: v1,v2

I have a JSON file in.txt with lines like {"k1":"v1","k2":"v2"} and I want to create from it a CSV file out.txt with lines v1,v2. The JSON file may contain more than 10 key/value pairs, so I prefer a solution that doesn't require specifying each key…
Serg
  • 13,470
  • 8
  • 36
  • 47
2
votes
1 answer

JQ error: is not defined at when trying to add values to jq template

I have a .jq template that I want to update values under the samples list, formatted as: { "test": "abc", "p": "1", "v": "1.0.0", "samples": [ { "uptime": $uptime, "curr_connections": $curr_connections, …
nobrac
  • 372
  • 1
  • 6
  • 16
2
votes
1 answer

AWS CLI / jq - transforming JSON with tags, and showing information even for non-defined tags

I'm facing an issue when trying to process output of 'aws ec2 describe-instances' command with 'jq', and I really need some help. I want to transform JSON output into CSV file with the list of all instances, with columns…
2
votes
1 answer

JQ search object with regex

I've been playing around with JQ https://jqplay.org to extract JSON data and I saw the test operation that allows me to use regex to extract data. In below sample run, I passed in regex pattern "^progressive$" into test to search for data: DATA: [ …
Nam Nguyen
  • 5,668
  • 14
  • 56
  • 70
2
votes
1 answer

How to create key:value list from JSON? Key name should contain some values from object itself

I'm trying to parse JSON and store certain values as metrics in Graphite. In order to make my Graphite more user-friendly I have to form a metric name, that contains some values from its object. I got working solution on bash loops + jq, but it's…
phear
  • 55
  • 4
2
votes
5 answers

Extract primary and secondary numbers for each ID and make a JSON string

I have two files as shown below: In general I will have more than three client IDs and primary and secondary numbers for each ID will be around 50-60. primary.txt {1=[0, 273, 546, 819], 2=[274, 1, 820], 3=[1016, 275, 821]} This means client ID 1…
user1950349
  • 4,738
  • 19
  • 67
  • 119
2
votes
3 answers

jq: translate array of objects to object

I have a response from curl in a format like this: [ { "list": [ { "value": 1, "id": 12 }, { "value": 15, "id": 13 }, { "value": -4, "id": 14 } ] }, …
Thomas
  • 871
  • 2
  • 8
  • 21
2
votes
1 answer

Alternative for jq

I am running a script which requires the jq command. It looks something like this:- devHubSfdxAuthUrl=$(sfdx force:org:display --verbose -u $DEV_HUB_USERNAME --json | **jq** -r .result.sfdxAuthUrl) JQ is not installed in my PC. Actually I am…
Skms
  • 43
  • 1
  • 7
2
votes
1 answer

Add multiple parent keys to json array

I have a json file, example.json: [ [ "126", 1522767000 ], [ "122", 1522859400 ], [ "126", 1523348520 ] ] ...and would like to add multiple parent items with the desired output: { "target": "Systolic", …
TryTryAgain
  • 7,632
  • 11
  • 46
  • 82