CSV/PPrint output/conversion from json via the command line (linux)
I'd like to get a csv/prettyprint output from the following json.{"count": 28,"data": [ {"id": 100920,"name": "bam","_embedded": {"addresses": [ {"address": "10.244.134.115" } ] } }, {"id":...
View ArticleUsing zsh and ace to pull metadata from epub using recursion [duplicate]
I'm trying to pull a bunch of metadata from a bunch of epubs. I'm on a Mac, using Ace by Daisy.So far I have:#!/bin/zshif [[ -e ./report.txt ]]; then rm ./report.txtfititles=("ISBN"...
View ArticleHow do I handle child objects properly with jq map()
I'm currently trying to build a pipeline to process Windows .evtx binary logs into usable JSON for easy searching and filtering on Linux, but due to going through xml, there is data that needs to be...
View ArticleJQ issues with comments on Json file
I'm using JQ https://stedolan.github.io/jq/ to work in bash with my json and when I read the json is throwing me an error parse error: Invalid numeric literal at line 2, column 5=Since my json has some...
View ArticleHow to filter values from a list in JSON with jq where some Id value does not...
I would like to filter DNSNames where Id does not start with the DNSName.Given the following JSON:[ {"Id": "9580cf2dd3161c0e33d8c04a4e84384e28784af65e55c1e84899d9da797902be","NetworkSettings":...
View ArticleAdd new element to existing JSON array with jq in a shell script: problem...
as described in "Add new element to existing JSON array with jq" I am using this jq form to add elements to a JSON array.This works fine in the command line. Short minimal version here:jq '."schemes"...
View ArticleIterating through JSON array in Shell script
I have a JSON data as follows in data.json file[ {"original_name":"pdf_convert","changed_name":"pdf_convert_1"}, {"original_name":"video_encode","changed_name":"video_encode_1"},...
View Articleconverting lines to json in bash
I would like to convert a list into JSON array. I'm looking at jq for this but the examples are mostly about parsing JSON (not creating it). It would be nice to know proper escaping will occur. My list...
View ArticleUpdating values in JSON array using jq
Using jq, I am trying to update the value of each object in an array, the new value calculated from the value of other keys in the same array, and returning the whole updated JSON.Test data saved in...
View ArticleSQL-style GROUP BY aggregate functions in jq (COUNT, SUM and etc)
Similar questions asked here before:Count items for a single key: jq count the number of items in json by a specific keyCalculate the sum of object values:How do I sum the values in an array of maps in...
View ArticleExtract data and sibling node from sub-array
I am trying to parse the output of AWS CLI describe-volumes - the raw output looks something like this:{"Volumes": [ {"Attachments": [ {"Device": "/dev/xv1d","InstanceId": "i-abcdef1234","State":...
View ArticleSelect objects based on value of variable in object using jq
I have the following json file:{"FOO": {"name": "Donald","location": "Stockholm" },"BAR": {"name": "Walt","location": "Stockholm" },"BAZ": {"name": "Jack","location": "Whereever" }}I am using jq and...
View ArticleHow do I print a parent value of an object when I am already deep into the...
Say I have the following JSON, stored in my variable jsonVariable.{"id": 1,"details": {"username": "jamesbrown","name": "James Brown" }}I parse this JSON with jq using the following:echo $jsonVariable...
View ArticleRecursive search for array with matching value
I am trying to use jq to find the layout of the currently active container in i3. i3-msg -t get_tree returns a recursive structure of containers with .layout and .focused properties. The trick is that...
View Articlejq to replace text directly on file (like sed -i)
I have a json file that needs to be updated on a certain condition. Sample json{"Actions" : [ {"value" : "1","properties" : {"name" : "abc","age" : "2","other ": "test1" } }, {"value" :...
View ArticleCan I pass a string variable to jq rather than passing a file?
I want to convert JSON string into an array in bash.The JSON string is passed to the bash script as an argument (it doesn't exist in a file).Is there a way of achieving it without using some temp...
View Articleget the first (or n'th) element in a jq json parsing
I can get the 1st element in a JSON inside []$ echo \'[{"a":"x", "b":true}, {"a":"XML", "b":false}]' | \ jq '.[1]'{"a":"XML","b": false}But if the json is already disassembled (for instance, after...
View Articlejq: selecting a subset of keys from an object
Given an input json string of keys from an array, return an object with only the entries that had keys in the original object and in the input array.I have a solution but I think that it isn't elegant...
View ArticleJoin multiple objects with one to many relationship
Imagine the following data (array of users which can have many roles, each user object has multiple roleIDs referenced and an array of role definitions):{"users": [ {"id": 1"roles": [ 1, 2 ] }, {"id":...
View ArticleDetermine if any value exists matching a filter expression while treating an...
I'm trying to determine whether a jq expression refers to no items at all, without collapsing null and empty.As I understand it, .foo? should be identical to try .foo catch empty. Because catch empty...
View Articlejq : Generate UUID in field
I have a requirement to tag records uniquely with UUIDs (for a correlation id). I cant see a direct way to do this via the options, is such a thing possible? If not, is there some kind of workaround...
View ArticleJQ: Select multiple conditions
I have a json and at the moment using select to get only the data which match one condition, I need to filter based on more conditions.For e.g:.[] | select((.processedBarsVolume <= 5) &&...
View ArticleParse error when text is split on multi lines: "control characters from...
I'm getting a "parse error" when I split a text line on multiple lines and show the JSON file on screen with the command jq . words.json.The JSON file with the text value on a single line looks like...
View ArticleHow 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 ArticleHow to check for presence of 'key' in jq before iterating over the values
I get Cannot iterate over null (null) from the below query because .property_history is not present in result object.How do I check for the presence of .property_history key before proceeding with...
View ArticleComparing two json files : shell scripting
I'm comparing two json files which look like:[ {"type" : 1,"children" : {"nsubj" : {"role" : "topic","POS" : ["noun" ] } },"role" : "vehicle","POS" : ["noun" ] },but there are differences between the...
View ArticleHow to get all objects of JSON array with specific keys using jq? [closed]
{"mainKey": "mainValue","date": "X","values": [ {"keyType1": "someValueX" }, {"keyType1": "someValueY" }, {"keyType2": "someValueZ" }, {"keyType2": "someValueC" }, ]}I need to get all values of objects...
View Articlejq: treat single object as 1-element array
I have several .json files (or rather, .xml files pre-parsed by xq/yq) that I want to parse. Unfortunately, the element I want to read (.size) can be inside an extra array (in which case I'd select one...
View ArticleJQ will not deep copy arrays with recursive algorithm
When using this algorithm:jq -s 'def deepmerge(a;b): reduce b[] as $item (a; reduce ($item | keys_unsorted[]) as $key (.; $item[$key] as $val | ($val | type) as $type | .[$key] = if ($type == "object")...
View ArticleCan `jq` be forced` to take slightly malformed JSON body?
I like using :!pbpaste | jq to see my JSON objects when reading logs in vim.But it often throws the following error with the slightest inconvenience in the JSON body.jq: parse error: Invalid numeric...
View Article