CSV to JSON using jq
If you have a csv dataset like this:name, age, genderjohn, 20, malejane, 30, femalebob, 25, maleCan you get to this:[ {"name": "john", "age": 20, "gender": "male"}, {"name": "jane", "age": 30,...
View ArticleRemove 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 ArticleHow 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 Articlejq: error Cannot index string with string "value"
Given:MY_JSON=$(cat <<EOF{"schema": "my.schema","properties": [ {"type": "new.data","value": {"labels": {"ofasd.io/arch.amd64": "supported","ofasd.io/arch.arm64":...
View ArticleMapping 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 ArticleUsing 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 ArticleHow 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 ArticleUsing 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 ArticleJQ: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 Articlejq 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 Articlejq 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 ArticleJQ 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 ArticleUsing 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 ArticleHow 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 ArticleGet 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 ArticleParsing 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 ArticleExtract "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 ArticleSplit 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 ArticleSorting 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 ArticleHow 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