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

jq how to create a dynamic select list

I'm wondering how you can I create a dynamic select statement to be used with jq. I want to be able to search a result based on names of people that I provide to my script....

View Article


How to add array from object's keys in jq

I want to add bundleDependencies from the dependencies's keys by using jq.json_string="$(cat <<'END'{"name": "hello","dependencies": {"progress": "^2.0.0","tar": "^6.2.1" }}END)"Here is the...

View Article


How to clear all object keys's value in jq

I want to clear all values from "dependencies" by using jq:json_string="$(cat <<'END'{"name": "hello","dependencies": {"progress": "^2.0.0","tar": "^6.2.1" }}END)"Here is the expected...

View Article

How do I use an element in a subfunction?

I'm trying to use the sub function to search/replace, but using JSON elements rather than literals.Here's a simple example JSON:{"example": {"search_for":...

View Article

Get unique objects and arrays based on key value

Is there a way to return a unique object/array when duplicates exist? Here's what I'm trying to do.I have a payload like this:{"data": [ {"account":...

View Article


Remove duplicates from JSON arrays

I want to remove the duplicates from each array in this JSON:{"abc": ["five" ],"pqr": ["one","one","two","two","three","three","four","four" ],"xyz": ["one","one","two","two","four" ]}Output I am...

View Article

Remove Duplicate Array Values

I am using the following jq query to extract the AWS ARN and associated protocols. However I only need the ARN to be listed once followed by the ports and protocolsmy code is jq -r '.Listeners[] |...

View Article

How to ignore duplicated array items in jq

I want to set bundleDependencies by using jq:json_string="$(cat <<'END'{"name": "hello","dependencies": {"progress": "^2.0.0","tar": "^6.2.1" },"devDependencies": {"node-fetch": "~2.6.1","yargs":...

View Article


JQ can't parse \u2022 character

I'm trying to perform a bulk upload to Elasticsearch (around 1mln documents). In order to do that, I'm using jq to reformat the JSON file extracted from MySQL database and curl to post the data to...

View Article


Jq create object fails when key is missing

I have two example filesexample1:{"label": "Example1","attributes": [ {"objectTypeAttribute": {"name": "Created"},"objectAttributeValues": [ {"value": "create time 1" } ] }, {"objectTypeAttribute":...

View Article

Install jq JSON processor on Ubuntu 10.04

Is there a way to install jq JSON processor on Ubuntu 10.04?I Tried the usual sudo apt-get install jq but got the error E: Couldn't find package jq

View Article

How to sort this json file with either jq or sed

{"adfdasfdafdfds": {"amount": 43,"mints": ["adfdasffd","dsafdsafdsfds" ] },"dfsfsdfdsf": {"amount": 1020,"mints": ["dfsfsads" ] },"sdfsdfdfgf": {"amount": 1,"mints": ["fsfdsfdfds" ]How to sort this...

View Article

How to exclude a particular subtree from processing descendants in jq

I have the following json input:{"to_exclude": {"x": "something","aa": {"x": "something","aaa": {"x": "something" } } },"a": {"x": "something else","aa": {"x": "something else","aaa": {"x": "something...

View Article


JQ: How to convert a very nested JSON file (tree like), in CSV with same key...

I have a PDF bookmark structure (tree like), which looks like this:Content Author 1 Piece 1 Piece 2 Author 2 Piece 3 Piece 4 Movement 1 Movement 2 Movement 3 Piece 5Using qpdf, it could be formatted in...

View Article

Apply jq functions conditionally to matching and non-matching JSON subtrees

I want to apply one function to all descendants of a particular node in a tree, and a different function to all other nodes, in the following way:if path_matches(.deep.path.matching) then...

View Article


Pass parameterized functions as callbacks to `jq` function

I'd like to dynamically pass parameterized processing functions as callbacks to a selective traversing function (process_matching_and_others).In the example below, that's based on this excellent answer...

View Article

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 Article


Make jq output an escaped sequence [duplicate]

I can't seem to get jq to escape a TAB character for me properly. This is a json I'm working with:{"api01": {"before": {"path": "api01","user": "admin" } },"server01": {"before": {"path":...

View Article

JQ return exit boolean instead of exit status code

I have following scriptgrep -e . testFile |jq -e ".fundingMoved.\"com.test\".map.\"java.util.HashMap\" |if .TRANSACTION_DESTINATION? then(.AGREEMENT_OWNING_ORG | startswith(\"MXN\")) and...

View Article

How to increase depth limit of jq?

When trying to minify a deeply nested JSON file (~10k deep) using jq I got a parse error:$ jq -c . <input.json >minified.jsonparse error: Exceeds depth limit for parsing at line 227263, column...

View Article

Invalid numeric literal when running jq from script via crontab

I have a shell script that runs fine from the command line but throws a error when it's run from a cronjob. What could be causing this error?The following includes the cron, the script, and the error...

View Article


How to merge 2 JSON objects from 2 files using jq?

I'm using the jq tools (jq-json-processor) in shell script to parse json.I've got 2 json files and want to merge them into one unique fileHere the content of files:file1{"value1": 200,"timestamp":...

View Article


Convert sequence of JSON lines (JSONL) to JSON array

I have a file where each line is a JSON object. I'd like to convert the file to a JSON array.The file looks something like this:{"address":"email1@foo.bar.com", "topic":"Some...

View Article

How to check if element exists in array with jq

I have an array and I need to check if elements exists in that array or to get that element from the array using jq, fruit.json:{"fruit": ["apple", "orange","pomegranate","apricot","mango" ]}cat...

View Article

JQ how to print newline and not newline character from json value

I have some logs that output information in JSON. This is for collection to elasticsearch.Some testers and operations people want to be able to read logs on the servers.Here is some example...

View Article


Select object from list where value is elsewhere in the JSON

Let's say I have a bit of JSON that looks like this{"fish": [ {"name": "pike","version": 1 }, {"name": "haddock","version": 2 } ],"current_fish_version": 2}And I wanted to get the name of the fish with...

View Article

Using jq to parse and display multiple fields in a json serially

I have this Json{"users": [ {"first": "Stevie","last": "Wonder" }, {"first": "Michael","last": "Jackson" } ]}Using jq I'd like to display first and last name serially. Like so -Stevie WonderMichael...

View Article

Replace \n with space in jq query/command output without tr and sed commands

With input.json:{"server1": {"name": "server1","property": "ENABLED" },"server2": {"name": "server2","property": "ENABLED" },"server3": {"name": "server3","property": "ENABLED" },}The following jq...

View Article

Printing multiple values on the same line

I'm trying to parse a JSON document and print a couple of values on the same line. Is there a way to take this document:{"fmep": {"foo": 112,"bar": 234324,"cat": 21343423 }}And print:112 234324I get...

View Article



jq: error (at :1): Cannot index string with string "prerelease" [closed]

full error explanation>The script tries to download https://api.github.com/repos/openapitools/openapi-generator/releases and parse the latest version, but the download sometimes can fail and the...

View Article
Browsing latest articles
Browse All 575 View Live


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