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

Is it possible to use jq to sort_by then sort_by again by sub item

I have the following json: [ { "SG": [ { "Id": "17", "GroupName": "fistGN", "Permissions": [ { "Port": 80, "Protocol": "tcp" }, { "Port": 8080, …
douglaslps
  • 8,068
  • 2
  • 35
  • 54
2
votes
3 answers

Passing key and values to external command from jq

What I'm trying to do: Use jq to pass along parameters to ffmpeg in a bash script. Have a JSON in this external file that I generate regularly. { "streams":[ { "track":"/var/www/html/stream1.m3u8", …
C.Astraea
  • 185
  • 4
  • 16
2
votes
2 answers

Elegant way to select nested objects with the associated key based on a specific criteria

Given an example document in JSON similar to this: { "id": "post-1", "type": "blog-post", "tags": [ { "id": "tag-1", "name": "Tag 1" }, { "id": "tag-2", "name": "Tag 2" } ], "heading": "Post 1", …
zrvan
  • 7,533
  • 1
  • 22
  • 23
2
votes
1 answer

How to move value of JSON element into subelement using bash

I have an interesting problem. I have this document: { "correlationId": "6298865a73b477106c98d021", "leg": 0, "tag": "sent", "offset": 322858, "len": 178, "prev": { "page": { "file": 10352, "page": 2 }, "record":…
Reddy SK
  • 1,334
  • 4
  • 19
  • 27
2
votes
1 answer

JQ -c / --compact-output not working properly? Json Parsing

I was just introduced to JQ in a question I posted about an hour ago, I'm parsing a very large database however, with JQ the output looks like this: "removedforprivacy@gmail.com" "john" "smith" null null "123 road st" null "Columbia" …
RayCrush
  • 29
  • 2
  • 12
2
votes
2 answers

Convert even odd index in array to key value pairs in json using jq

I'm trying to use jq to parse Solr 6.5 metrics into key value pairs: { "responseHeader": { "status": 0, "QTime": 7962 }, "metrics": [ "solr.core.shard1", "QUERY./select", "solr.core.shard2", "QUERY./update" ... ] } I'd like to pick even odd entries…
2
votes
2 answers

Jq: appending an object from 1 file into another file

Using jq, how can I take a json object from a file (input_02.json), and append it to output.json, while retaining everything already in output.json (e.g. an object originating from file input_01.json). The object to be appended in both cases is…
John Bergqvist
  • 852
  • 13
  • 38
2
votes
1 answer

Jq: Create new empty object with existing property as its key

If I have a json file as follows: { config: { name: "test1" } } How would I use jq to create an empty object named after "test1" in a new file? i.e. test1: { }
John Bergqvist
  • 852
  • 13
  • 38
2
votes
1 answer

json - query with conditions

I have following json: { "id": "1", "name": "profile1", "userId": "0", "groupId": "3", "attributes": [ { "id": "104", "name": "Enable", "value": "1" }, { "id": "105", "name": "TargetNode", …
Chris
  • 939
  • 2
  • 11
  • 22
2
votes
1 answer

Using jq to convert array of strings into array of objects

Input json: [ { "Authors": "Author1, Author2, Author3", "Affiliation": "Here, There, Everywhere" }, { "Authors": "Author4, Author5", "Affiliation": "Nirvana, Utopia" } ] Desired output: { "authors": [ { …
Mat Ford
  • 73
  • 1
  • 8
2
votes
5 answers

shell-out value to md5 (crypto) function

I'm looking for a solution where I'm building out a JSON record and need to generate some text in JQ but pipe this text to an MD5 sum function and use it as a value for a key. echo '{"first": "John", "last": "Big"}' | jq '. | { id: (.first + .last)…
Silas Paul
  • 15,857
  • 2
  • 14
  • 11
2
votes
1 answer

add object to dynamic key using JQ

I'm looking to build object using jq and add object key to dynamic key and I could not figure out. Here is my sample script: #!/bin/bash -e environments=('development' 'stage' 'production') regions=('us-east-1' 'us-west-2') tree='{}' for…
Nam Nguyen
  • 5,668
  • 14
  • 56
  • 70
2
votes
1 answer

jq special characters in nested keys

I have a json similar to the following: { "_source" : { "index-pattern" : { "fields" : "" } } } I'm trying to modify fields, but chaining the . identity operator, such as 'jq ._source.["index-pattern"].fields'…
user9269299
  • 21
  • 1
  • 2
2
votes
4 answers

Use grep for extract text between two word

I hava a file: { "test1": [ "test_a", "test_b", "test_c" ] } I am trying to extract the text that exists between "test1": [ and ] I'm trying this command: cat test | grep -o -P '(?<=test": [).*(?=])' But it's not…
Crazy
  • 139
  • 3
  • 12
2
votes
2 answers

jq query with condition and format output/labels

I have a JSON file: [ { "platform": "p1", "id": "5", "pri": "0", "sec": "20" } ] [ { "platform": "p2", "id": "6", "pri": "10", "sec": "0" } ] I can to format it to the form: $ jq -c '.[]|{PLATFORM: .platform,…
1 2 3
99
100