Quantcast
Browsing all 524 articles
Browse latest View live

Sorting a JSON array by an arbitrary order using jq

Given this JSON data in the file data.json:[ { "id": 1, "entityType": "cat" }, { "id": 2, "entityType": "dog" }, { "id": 3, "entityType": "bird" }, { "id": 4, "entityType": "cat" }]How would return an...

View Article


How can I use a jq query to extract a string from this Ansible dictionary?

So I have the following tasks in my playbook- name: gather package facts package_facts:- name: send packages containing 'fence-agents' to a file lineinfile: path: /etc/leapp/transaction/to_remove line:...

View Article


Pipe commands not getting killed after head exits

So, I'm not sure if the commands are actually important, but for background this is the command I was running:aws s3 ls s3://REDACTED/ | jq -nR '[inputs | split(" +"; null).[3]] | reverse.[] | "bkt...

View Article

jq - difference in behavior between Linux and Windows version

Using jq 1.7 in Linux and Windows. The following run fine in Linux (version 5.10.228-219.884.amzn2.x86_64), but gives error "'.[]' is not recognized as an internal or external command, operable program...

View Article

how to return specific properties relative to each other jq 1.5

I have an input:$ ip -json route show > ip_routes.json$ cat ip_routes.json # I've pretty printed this for easier reading.[ {"dst": "default","gateway": "10.1.201.1","dev": "eth0" }, {"dst":...

View Article


How to Subtract Objects in jq?

We can merge two objects recursively with * operator. For example like this: jq '.[0] * .[1]' -s a.json b.json. The only problem (I realized) with it is it doesn't merge the arrays. But some guys did...

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

How to properly format CSV output using jq and sed?

I'm trying to process a JSON file and convert it to a CSV format using jq and sed. My goal is to replace decimal points with commas in one of the fields and ensure the output is properly formatted with...

View Article


Filter jq for reshaping a JSON array into a nested representation of...

I have a JSON source like this, in which the root array can vary both in number of elements and in parent relationships, inferred from the values in “id” and “parent” keys (while the “type” key...

View Article


Get sub-objects in JSON where key values unknown

I have the following JSON generated from a command. The JSON is composed of objects where the key is a random string, and I want to access data in each of those objects. Any thoughts on how to do that,...

View Article

Object item and nested array items on same output line

I've got some data that looks like this:{"data": [ {"startTime": "2024-12-31T00:00:00Z","data": [ {"one": "a","two": 1125.000 }, {"one": "b","two": 2119.000 }, {"one": "c","two": 0.000 } ] },with...

View Article

Ignore Unparseable JSON with jq

I'm using jq to parse some of my logs, but some of the log lines can't be parsed for various reasons. Is there a way to have jq ignore those lines? I can't seem to find a solution. I tried to use the...

View Article

JQ: exclude specified embedded keys

From the following input:{"key1": {"key_x": "1", ..."key_z": "2" },"key2": {"key_x": "2", ..."key_z": "3" }}I would like to exclude all keys with the name "key_x" so the result should be{"key1": {...

View Article


How to install JQ on Mac on the command line?

I need to know the most efficient way of installing JQ on Mac (El Capitan). The code is downloaded to my Mac but I would like to know how I can install and operate it via the command line.

View Article

How can I use jq to extract the first strings inside an object, while...

example data.json file:{"JSON_KEY": { "SOME_TITLE": {"RANDOM_STRING1": {"label": "value","units": {"subunits": [ {"item1": "1", "item2": "2"}, {"item3": "3", "item4":"4"} ] } } } }}Imagine this...

View Article


Using jq to include data taken from two filtered array elements into a single...

Given input JSON like this (there's a lot more to it really, but I've stripped the fields that aren't of any interest:{"modules": {"data": [ {"id": "aod_play_area","data": [ {"titles": {"primary":...

View Article

How to merge consecutive JSON objects without shared keys

I have a JSON file with a bunch of objects and after each, there's a smaller object with extra data. They don't share any information, so the position is the only thing connecting them. This...

View Article


jq: How to output quotes on raw output on Windows

Using raw output, I have to quote some values of the output.For example,echo [{"a" : "b"}] | jq-win64.exe --raw-output ".[] | \"Result is: \" + .a + \".\""generatesResult is: b.but how can I generate...

View Article

docker image pull stedolan/jq fails on deprecation

Error seen is:+++ docker run --rm -i stedolan/jq '.architectures.x86_64.artifacts.qemu.formats["qcow2.gz"].disk.location'+++ tr -d '"'Unable to find image 'stedolan/jq:latest' locallylatest: Pulling...

View Article

parsing a JSON containing several stringified jsons using Batch and JQ

I am creating an integration between two websites my company uses to track data. The API for one of the sites (Monday.com) has returned a json with several smaller json values stored as strings inside...

View Article
Browsing all 524 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>