How 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 Article