Quantcast
Channel: Active questions tagged jq - Stack Overflow
Browsing latest articles
Browse All 515 View Live

How do I select multiple fields in jq?

My input file is newline delimited JSON (ndjson) looking something like this:{"login": "dmaxfield","id": 7449977, ...}{"login": "dmaxfield","id": 7449977, ...}I can get all the login names with this :...

View Article


Mapping from file in jq

I'm trying to use jq to look up data from a json file with account mappings. So given an account number as input, I want to look up it's name from a file, and it needs to handle the account not being...

View Article


Using jq, how to transform a nested data structure into a "flat" command-like...

I have the following JSON structure that represents a database schema:{"db": [ {"tables": [ {"name": "tblFoo","cols": [ {"name": "created","types": [ { "data_type": "timestamp" } ] }, {"name":...

View Article

How to filter using jq array of strings which contains a specific value

How do I filter using jq which contains string "edp-api-dev"{"serviceArns":...

View Article

Using jq to create JSON objects/dictionaries

In my bash script I have a dictionary/map like:k1: v1k2: v2k3: v3Can I possibly use jq --slurp or jq --raw-input to actually convert this to JSON like this:{"k1": "v1","k2": "v2","k3": "v3"}possibly by...

View Article


JQ:How to remove items from json array with conditions?

I have the following few json array objects that Id like to filter using a single jq command.{"Sid": "bla1","Effect": "Allow","Principal": {"AWS": "*" },"Action": "blabla","Resource":...

View Article

jq Conditional output

I'm using jq to play with json. I was wondering how to conditionally print something in that.Say I am interested in a field call geo. I used the following command and find out there is only one entry...

View Article

jq select elements with array not containing string

Now, this is somewhat similar to jq: select only an array which contains element A but not element B but it somehow doesn't work for me (which is likely my fault)... ;-)So here's what we have:[...

View Article


JQ Select items that do not match string

I've got a group of AWS instances that I'm parsing via aws ec describe-instances. I'm looking to trim out all the records whose IP's do not start with '10.10'.aws ec2 describe-instances --no-paginate...

View Article


Using jq with Jenkins pipeline

In my use case i'm running a pipeline which calls aws cli via the withAWS plugin. I use jq to get the needed data, Now the sh returns the output as String. How do i convert this output to json object...

View Article

How to prettify json with jq given a string with escaped double quotes

I would like to pretty print a json string I copied from an API call which contains escaped double quotes.Similar to this:"{\"name\":\"Hans\", \"Hobbies\":[\"Car\",\"Swimming\"]}"However when I execute...

View Article

Get intersection of arrays in JQ

I'm new to jq,and would like to get the intersection of two arrays (similar question BUT with different approach: link).I managed to get the union of two arrays and addition of two...

View Article

Parsing JSON with Unix tools

I'm trying to parse JSON returned from a curl request, like so:curl 'http://twitter.com/users/username.json' | sed -e 's/[{}]/''/g' | awk -v k="text"'{n=split($0,a,","); for (i=1; i<=n; i++) print...

View Article


Extract "packages" key from skopeo output with jq

I'm trying to extract the list of packages from skopeo inspect output, but this does not seem to work:❯ skopeo inspect docker://ghcr.io/ublue-os/bluefin-dx:gts | jq...

View Article

Split a JSON array into multiple files using command line tools

Suppose we have a JSON array of length 5 and we want to split the array into multiple arrays of length 2 and save the grouped items into different files, using linux command line tools. I tried it by...

View Article


Sorting and comparing json files with ./jq

I am trying to compare two long json files with WinMerge by using QueryJSON plugin.Properties in those files are in random order.That parameter for .\jq does work, but nested objects are not...

View Article

How to convert a json string into an individual character array in bash?

I have a json string that I need to convert into an array for passing a password in. Current issue is I need to do this for many usersCurrent json looks like this which was generated from [...

View Article


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

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
Browsing latest articles
Browse All 515 View Live


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