jq 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 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 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 ArticleJSON to plain text using jq
Let's say i got the following json response:{"author": "tomek","title": "helloworld","test": "sampletextonetwothree"}Is it possible to display something like this: (using...
View ArticleIgnore 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 ArticleHow to exclude the elements from one array that exist in another array by...
Assuming two json files:a.json[ {"category": "utils","name": "yq" }, {"category": "utils","name": "yq4" }, {"category": "utils","name": "yip" }, {"category": "utils","name": "jq" }, {"category":...
View ArticleBash compile output into a csv using jq
I am writing a Bash script to create a csv from a sample inconsistent json data but running into a bunch of issues.My json data looks like this :json_data='[ {"ResourceARN": "arn","Tags": [ {"Key":...
View Articlejq command with several tables in the json path
My (huge) input file has many entries , what I want to extract is structured like that:{"vulnerabilities": [ {"parentAlert": {"affectedVersions": [ {"answers": [ {"willBeFixed": true,"fixedInPackage":...
View Articlejq: C:/cygwin64/bin/jq.exe: error while loading shared libraries: ?: cannot...
jq fails with:$ jqC:/cygwin64/bin/jq.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directoryHow can I find out which libary was missing?
View ArticleEscape Regex special characters in jq
I want to do search and replace in a larger jq program.The problem is that search may contain special characters that are interpreted as regex functionality, which I dont want. Special characters...
View ArticleConverting a CSV file into a nested JSON file using ./jq
I am hoping I can get an answer on this question. I am using ./jq to convert a CSV file into a file of JSON objects. Each line of the CSV input represents a JSON object. A sample of the CSV input is as...
View ArticleAdd new element stored in a variable to existing JSON array with jq
I am working on creating an adaptive card dynamically. I have the skeleton on the card in JSON and I want to add entries to it (each entry will be a JSON object inside the "body" of the below schema)....
View Articleusing jq to assign multiple output variables
I am trying to use jq to parse information from the TVDB api. I need to pull a couple of fields and assign the values to variables that I can continue to use in my bash script. I know I can easily...
View ArticleHow to run jq from gitbash in windows?
I have gitbash in Windows. I am trying to run jq but its giving me error.$ ./jq-win64.exe jq parse error: Invalid numeric literal at line 2, column 0Intention: I want to use jq to parse json.
View Articlejq: error: syntax error, unexpected IDENT, expecting $end (Unix shell quoting...
cat explorer/connection-profile/test-network.json | jq ".organizations.Org1MSP.adminPrivateKey.path |= 44ab"jq: error: syntax error, unexpected IDENT, expecting $end (Unix shell quoting issues?) at...
View ArticleConverting JSON to CSV using jq with header line
I have a task to convert a JSON file to a CSV with a header at the top. The header has to be in a particular order. So the order of the keys in the JSON file will be in different order than the header...
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 filter list based on prefix list?
I have a list of hostnames and I want to filter out all hostnames that end in any of a given List of domains. For example for the hostnames...
View ArticleHow do I portably parse a JSON file using libjq?
Consider the following code snippet based on libjq.#include <stdio.h>#include <stdlib.h>#include <jq.h>#include <jv.h>int main(void) { jq_state *jq = jq_init(); if (!jq) {...
View ArticleSelecting parent objects based on nested child properties
I have a JSON document as a result of scanning a DVD. It contains a TitleList array, each entry of which contains a ChapterList array, each entry of which has a Duration object. I want to select a...
View Article