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 filter- unexpected "null"s

input json: { "id": 381, "name": "Module", "value": "C-A", "locked": false } { "id": 381, "name": "Module", "value": "", "locked": false } { "id": 381, "name": "Module", "value": "", "locked": false } And I want to remove…
Chris
  • 939
  • 2
  • 11
  • 22
2
votes
1 answer

Modify array elements while grouping by a specific key using jq

Is it possible to modify/replace array elements while grouping by a specific key (.[].Parameter.Id) such that this array: [{ "Id": 48, "Parameter": { "Id": 17 } }, { "Id": 196, "Parameter": { "Id": 17 …
emrekgn
  • 624
  • 9
  • 25
2
votes
2 answers

Generate file and replace strings in template file in the generated files

I have a JSON file: { "header": { "uuid": "c578592a-a751-4993-9060-53f488597e59", "timestamp": 1522938800, "productionDateTime": "2018-04-05T14:33:20.000+00:00", "producers": { "operator": null, …
ltqbx
  • 33
  • 6
2
votes
2 answers

jq convert comma separated JSON objects into array

I have files which have N JSON objects and they are separated by comma (,) {"a":1},{"b":2},{"c":3},{"d":2},{"e":1},{"f":2} ... I would like to convert them into one JSON array with N objects using…
mike
  • 373
  • 3
  • 14
2
votes
1 answer

How to get the keyid of an object in a JSON file if one of the fields contains a specific string

I have the following JSON: { "201110131738QP27N": { "parent": 17, "name": "CentralServer", "status": "Active", "count": 6 }, "201803271459ICV69": { "name": "subaccount1", "status": "Active", "count": 1 }, …
2
votes
2 answers

jq: How to combine disjoint object values as a single object of key/value pairs?

If I have a JSON input data: input.json { "metadata": { "guid": "07f90eed-105d-41b2-bc20-4c20dfb51653" }, "entity": { "name": "first" } } { "metadata": { "guid": "da187e3a-8db9-49fd-8c05-41f29cf87f51" }, …
Steve Amerige
  • 1,309
  • 1
  • 12
  • 28
2
votes
2 answers

How to search JSON key that contains specific string with jq?

I have a JSON data: { "orderTotal_1": { "fields": { "button": { "actionDialog": null, "actionUrl": null, "clicked": false, "enable": true, …
Joe
  • 791
  • 1
  • 9
  • 24
2
votes
1 answer

Use jq to recursively select key names of an object

I have a JSON document that looks like: simple: 42 normal: description: "NORMAL" combo: one: description: "ONE" two: description: "TWO" arbitrary: foo: 42 I want to use a jq expression to generate the following: ["normal",…
Stephen Chu
  • 343
  • 2
  • 15
2
votes
1 answer

Jq getting output from nested hash

Hi I am trying to parse below hash with jq { "name": "a", "data": [ { "sensitive": false, "type": "string", "value": "mykeypair" }, { "sensitive": false, "type": "int", "value":…
2
votes
2 answers

Accessing field with jq that can be string or array

I have a large dump of data in json that looks like: [{ "recordList" : { "record" : [{ "Production" : { "creator" : { "name" : "A" } } }, { "Production"…
Tine
  • 35
  • 4
2
votes
2 answers

Unable to parse JSON file to CSV with jq-string ("") and array cannot be added

Here is output.json: https://1drv.ms/u/s!AizscpxS0QM4hJo5SnYOHAcjng-jww i have issues in sts:AsumeRole.Principal.Service part when have multiple Services Principal": { "Service": [ …
Milister
  • 648
  • 1
  • 15
  • 33
2
votes
1 answer

Use jq to Convert json File to csv

I am using curl to pull Alien Vault OTX pulses from their API, the initial output I receive is in json format and I need to convert this json into csv as so it can be read by some other software. I aim to use jq as many others have recommended it. {…
George
  • 23
  • 1
  • 6
2
votes
1 answer

Get child elements with their keys (jq)

Using jq, I would like to get all the children of the root element and include their keys. e.g. from this document: {"foo": [1, 2, 3], "bar": [4, 5, 6]} I would like to get: {"foo": [1, 2, 3]} {"bar": [4, 5, 6]} Using variations on array indexing,…
Synesso
  • 37,610
  • 35
  • 136
  • 207
2
votes
1 answer

jq match a regex

Let's say I have a json file, I run cat testTab.json | jq '.action.service.spec.task| select(.container) | .container' and it gives me { "image": "ubuntu:latest", "args1": "tail", "args2": "-f", "args3": "/dev/null", "mounts": { …
hichamx
  • 794
  • 3
  • 7
  • 18
2
votes
2 answers

Compare datetime inside variable with current datetime

I have the following line: for custom_field in $(jq -r '.issues[] | .fields.created' 1.json ); do echo $custom_field done Output: 2018-03-06T21:24:41.000+0000 2018-03-06T22:48:47.000+0000 How to compare current datetime with each output…
Milister
  • 648
  • 1
  • 15
  • 33