Quantcast
Browsing all 524 articles
Browse latest View live

Assigning incrementing numbers in order-preserving way

Using jq, I want to assign an incrementing number num to each element in the order they appear in the input, but keep the same number for elements that share a ref value with other elements.So...

View Article


How to use jq to merge a list of dictionaries into one dictionary

I'm developing jq expressions on the command line. (I plan to use the expression with pyjq in python to parse http requests.)The following command line:$ cat some.json | jq...

View Article


Flatten a JSON document using jq

I'm considering the following array of JSON objects:[ {"index": "index1","type": "type1","id": "id1","fields": {"deviceOs": ["Android" ],"deviceID": ["deviceID1" ],"type": ["type" ],"country": ["DE" ]...

View Article

Include element only if present

I am implementing a program accessing a REST API, which can be filtered server-side by passing in a jq-statement. My issue is with writing a jq filter that includes an element called...

View Article

Recursive search values by key in docker inspect output : Cannot index string...

I'm trying to recursively extract with jq the RestartPolicy from the docker inspect json output of a container.I tried this command adapted from this solution :$ sudo docker inspect...

View Article


How to convert a json response into yaml in bash

I read data from a json file with jq. I wanna append the results into a yaml file, but I dont get it working. I am quite new to shell programming. My goal is to append that "users" to an existing...

View Article

Process large JSON stream with jq

I get a very large JSON stream (several GB) from curl and try to process it with jq.The relevant output I want to parse with jq is packed in a document representing the result structure:{"results":[...

View Article

How to iterate and pick the each element in {} blocks

{ __name__: sc_pcd_g2version, container: mgmtbroker, endpoint: vxexporter, instance: 10.42.24.132:9116, job: prometheus, namespace: delivery, pod: chn1-d1-ac-0, service: prometheus }{ __name__:...

View Article


How to insert JSON into table beside a specific value using JQ

In this JSON snippet[ {"user":"user-1","videos":[ {"key":"key1","url":"url1" } ] }, {"user":"user-2","videos":[ {"key":"key2","url":"url2" } ] }]I want to add {"key":"key3","url":"url3"} under videos...

View Article


How to recursively print the path of all keys in jq

I'd like to get a list of all paths available in a JSON document, just to get an idea of the layout of a big json document.One liners preferred, of course a big jq/python program can do the...

View Article

how to parse a JSON String with jq (or other alternatives)?

I'm trying to get jq to parse a JSON structure like:{"a" : 1,"b" : 2,"c" : "{\"id\":\"9ee ...\",\"parent\":\"abc...\"}\n"}That is, an element in the JSON is a string with escaped json.So, I have...

View Article

Parsing nested json with jq - Cannot index string [duplicate]

I cannot work out what is happening here.I am using Amazon Secret Manager in a ec2 user_data bash script to retrieve a secret to be used on ec2 bootup.SECRET_VALUE=$(aws secretsmanager get-secret-value...

View Article

Remove last character from json output using JQ

I have a json that looks like this:{ "HostedZones": [ {"ResourceRecordSetCount": 2,"CallerReference": "test20150527-2","Config": {"Comment": "test2","PrivateZone": true },"Id":...

View Article


sort json object numerically by key

I have the following json format. It's basically a representation of the calendar:{"month1": {"day1":{...}, "day2": {...}}, "month2": {...}}I'd like to sort it such that both the months and the days...

View Article

using jq want to parse array nested inside object. But the entire object gets...

json ={"Country":"India","States": [{"Name":"TN","Cities":["city1","city2"]},{"Name":"KL","Cities":["city3","city4"]}]}query = {country:.Country,states: .States | (foreach .[] as $item (0;...

View Article


How can I put integer as an argument in jq?

I have been trying to use jq to parse a json file returned from the aws cli, but I'm stuck with the problem of referencing an array using the index number. I need to do this because I want to export a...

View Article

how to get the intersection of two JSON arrays using jq

Given arrays X and Y (preferably both as inputs, but otherwise, with one as input and the other hardcoded), how can I use jq to output the array containing all elements common to both? e.g. what is a...

View Article


The entire object gets duplicated in output when trying to parse array nested...

I have the following json data:{"Country": "India","States": [ {"Name": "TN","Cities": ["city1","city2" ] }, {"Name": "KL","Cities": ["city3","city4" ] } ]}jq expression:{ country:.Country,states:...

View Article

jq: adding nested object to a JSON

I have a json file containing several profiles:{"profile1": {"user": "user1","channel": "channel1","hook": "hook1" },"default": {"user": "user1","channel": "channel1","hook": "hook2" }}I want to use jq...

View Article

Why is JQ throwing a "cannot iterate over null" error at EOF?

i have a json array where each entry has this structure:{ inputarray: {[ {"header": "YouTube Music","title": "Watched Nu Nu Meta Phenomena","titleUrl":...

View Article
Browsing all 524 articles
Browse latest View live