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: How to convert flat json into nested one

I've been trying to re-arrange a pretty flat json into structure with more depth, so far without any success. Here's my source data: [ { "id": "27", "time": "2017-12-21 07:24:00", "service_name": "prices", "version": "61f4u8e", …
hugo387
  • 23
  • 3
2
votes
2 answers

Bash and jq nested loops on json

I try to use jq to parse a json file and use it in a bash script, but i'm having some difficulties. The…
MarvinLeRouge
  • 444
  • 5
  • 15
2
votes
1 answer

JQ - Replace string in full json

guys. I need to replace all occurrences of a string with a different string in the whole body of a JSON in JQ. Say in the following input JSON I want to replace the string "DEV" with "INT". How could I do this in JQ? Input JSON: { …
MadaIdo
  • 33
  • 1
  • 3
2
votes
2 answers

Extract UTF-uncoded binary data from JSON using jq

Say I have a JSON with a 0xb7 byte encoded as a UTF codepoint: {"key":"_\u00b7_"} If I extract the value of the "key" with jq it keeps the utf8 encoding of this byte which is "c2 b7": $ echo '{"key":"_\u00b7_"}' | ./jq '.key' -r | xxd 0000000: 5fc2…
salmin
  • 457
  • 3
  • 12
2
votes
3 answers

JQ - parsing field by hierarchy

I have very large json I want to extract sum of data from it using jq. I am trying every possible way but I think I am missing something here.. My Json subset: {"main": {"0": {"x": {"a":1}, "y": {"number of un-used":{"count":2} , "z":2}}, "1":…
gabi
  • 1,003
  • 5
  • 12
  • 30
2
votes
2 answers

Select elements before nth element with jq

I'm stuck on the following json with jq. The elements below are sorted descending by some timestamp (not included in the json). I need to select the ids before id X. E.g. select ids before id 1 should return 2, 3 and 5. [ { "id": 2, …
Bas Harenslak
  • 2,591
  • 14
  • 14
2
votes
1 answer

jq, locale and strptime: how to use properly

I have this input {"text": "05 april 2017"} If I run echo '{"text": "05 april 2017"}' | jq '.text|strptime("%d %B %Y")' I have the right result. If I set temporary my locale in italian with export LC_ALL=it_IT.utf8 and apply .text|strptime("%d %B…
aborruso
  • 4,938
  • 3
  • 23
  • 40
2
votes
1 answer

JQ filtering on fields in nested Objects

I have a large set of data, I am using JQ to construct the object that contains only the data I am interested in for a record. My problem is that I am starting to see duplicate objects, it seems my syntax is incorrect. I am working with an object…
Goldfish
  • 576
  • 1
  • 7
  • 22
2
votes
3 answers

jq flattening JSON arrays

This echo '{"a":[{"b":[{"c":"xxx"}]},{"b":[{"c":"yyy"},{"c":"zzz"}]}]}' | jq '.a[].b | map({"c": .c})' produces this: [ { "c": "xxx" } ] [ { "c": "yyy" }, { "c": "zzz" } ] How do I get a single output array like: [ { …
clay
  • 18,138
  • 28
  • 107
  • 192
2
votes
2 answers

Using jq to load one json file into the hash of another json file

I'm trying to figure out how to use jq to load the content of one json file into the hash of another file. E.g.: this file: { "annotations": {...}, "rows": [ {...}, {...}] } should be inserted into this file at the hash dashboard: { …
2
votes
1 answer

jq: how to select elements with different structure

I'm sure this is very simple, but I do not know how to do it with jq. I have a JSON like this one [ { "id": "109", "name": "aaa" }, { "id": "1098", "name": [ "bbb", "ccc" ] }, { "id": "2000", "name":…
aborruso
  • 4,938
  • 3
  • 23
  • 40
2
votes
3 answers

Passing JSON objects to jq arguments

Data sample - sample.json (full sample: https://pastebin.com/KFkVmc2M) { "ip": 3301234701, "_shodan": { "options": { "referrer": "7ae15507-f5cc-4353-b72e-5cc0b1c34c5e" }, }, "hash": -1056085507, …
user3086917
  • 97
  • 2
  • 12
2
votes
4 answers

jq: Turn json object values into arrays

I have got the following array of objects (this is just an excerpt, also the objects are bigger): [{ "DATE": "10.10.2017 01:00", "ID": "X", "VALUE_ONE": 20, "VALUE_TWO": 5 }, { "DATE": "10.10.2017 02:00", "ID": "X", …
2
votes
2 answers

How to properly chain multiple jq statements together when processing json in the shell such as with curl?

I am new to jq so if this is not a jq question or a json question please point me in the right direction. I am not sure of the correct terminology so it is making it hard for me to properly articulate the problem. I am using to curl to pull some…
Joseph Ishak
  • 1,194
  • 1
  • 9
  • 18
2
votes
2 answers

Map over two arrays with jq and merge objects inside

I have two arrays of identical length with objects in them: input: [[{foo: 1}, {foo: 23}], [{bar: 12, baz: 543}, {bar: -1}]] How do I tell jq to merge them into one array like below? output: [{foo: 1, bar: 12, baz: 543}, {foo: 23, bar: -1}]
heyarne
  • 1,127
  • 9
  • 33
1 2 3
99
100