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

Convert a simple JSON object to a properties file

I have a simple JSON object and would like to convert it into a properties file in bash.Input: {"foo": "bar","abc": "def ghi"}expected output:foo="bar"abc="def ghi"

View Article


Convert JSON to CSV, repeating parent value

There's a lot of discussion to convert JSON to CSV with jq, but can't find my situation.2 points really blocking me :Get key and value of valuePerDay by rowSort valuePerDay keys to unsure values always...

View Article

JQ: How to get just part of a JSON object? [duplicate]

How can I get my wanted output? I can't figure out how to preserve the object names (keys).I'm new to jq and I tried several flavors of jq's select/flatten/map/","/"keys as $k".../etc. but I'm not...

View Article

Merge two JSON files with jq, adding integers

I have two JSON files of the form:{"xFruits": {"views": 163,"all": {"xApples": {"views": 28,"eats": 10,"discards": 17 } } },"xVegetables": {"views": 134,"all": {"xBeans": {"views": 29,"eats":...

View Article

How to debug jq errors for parsing AWS price API

I'm trying to parse out some of the AWS price API json results and noticed that I'm getting some errors on string and object validation, but can't figure out how to debug which object or string jq is...

View Article


Check the amount of traffic on server, and then detects if the traffic has...

I've written a script in the bash to connect to servers via SSH and check their traffic. If the traffic significantly decreases, the script will send an email to the address specified in the...

View Article

How can i use jq to format json to csv?

I am trying to format this json data to CSV format, but I get this error: error (at <stdin>:0): Cannot index array with string "time". Here is a short version of my json data:{"latitude":...

View Article

Syntax when there is a space in the key

This is driving me nuts.I have a JSON that looks like this:{"gateways": [ {"DHCP": "On","External IPs": "46.244.46.66","Firewall": "On","NAT": "Off","Name": "gateway","Routed Networks": "photon,...

View Article


| . + in jq meaning

I'm not sure what the dot and plus sign after a pipe mean, and I haven't been able to find anything on the internet about this. For example, when looking up a title in a Json object, I would write| . +...

View Article


Using JQ how to append entry to dictionary type array in JSON or create it if...

I have ideal JSON:{"environments":[ {"name":"test","release":"2.0" }, {"name":"prod","release":"1.0" }, ]}This file could be in any state:It can be empty file with just empty object { }It can have...

View Article

Image may be NSFW.
Clik here to view.

JQ Cannot iterate over null

I am trying to create a jq that is dynamic in returning data.User Story: I have data with many fields and not named like I want. I want to be able to based on the data and schema transform the...

View Article

Match object with array key to exact values using jq

Match first object which has an array that contains exactly same values (it's should always be length of 2)Example:[ { "id": 242, "size": [500, 500] }, { "id": 234, "size": [500, 1920] }, { "id": 168,...

View Article

Converting csv to json with jq

I'm currently practicing converting plain text to csv, and them csv to json. I need to do the conversion only with jq and basic Linux commands.I didn't have any major problems converting plain text to...

View Article


Using JQ query how to update propery inside two nested arrays?

I tried this for 2 days but can't figure it out in any way.This is my JSON:{"items": [ {"name":"itemA","bins":[ {"bin_id":"b1","count":"11" }, {"bin_id":"b2","count":"22" } ] },...

View Article

Strange behaviour of the alternative operator //

Using JQ 1.5 I've problems understanding the output of the alternative operator // in a specific situation.Given this input:{"a": 42,"b": false,"c": null}I expected the expression (.a, .b, .c, .d) //...

View Article


Dump all key pair of a json with JQ

Today I have big troubles in parsing huge json files (bigger than a megabyte) with only pure bash functions (performance issues), so I would like to use JQ parser https://jqlang.github.io/jq/ to speed...

View Article

How to merge json object with same keys?

Here are the 2 items in one array:{"SysID": "12345","Name": "abc"}{"SysID": "12345","Name": "def"}{"SysID": "23456","Name": "hij"}{"SysID": "23456","Name": "klm"}{"SysID": "23456","Name": "nop"}I would...

View Article


jq how to merge multiple arrays?

I have the following data, the output of multiple jq pipes: [ {"Russia": 1073849 } ] [ {"Spain": 593730 } ] [ {"France": 387252 } ] [ {"UK": 371125 } ]My desired output is: [ {"Russia": 1073849 },...

View Article

Parse multilevel json into a csv using jq tool in unix

I have a multilevel json like so:{"id": "id123","details": {"prod": "prod123","etype": "type1" },"accounts": [ {"bankName": "bank123","accountType": "account123","openingBalance": "bal123","fromDate":...

View Article

Can not extract more than one key when looping over an array with jq in bash...

This works:#!/bin/sh -ecat << EOF > error.json[ {"path": "path1","path_with_namespace": "path_with_namespace1" }, {"path": "path2","path_with_namespace": "path_with_namespace2" }]EOFjq -c...

View Article

jq referencing an index/key with its inner values

I have a JSON similar to the following:File: my_data.json{"hosts": {"1.2.3.4": { "name": "name4", "env": "test", "options": "" },"1.2.3.5": { "name": "name5", "env": "prod", "options": "opt1,opt2"...

View Article


JQ print two arrays values using the same index

in the following example I have two arrays (timestamp and values) that are related by the same index, so timestamps[0] is related to values[0], timestamps[1] is related to values[1], ...{"timestamps":...

View Article


Nested Json invocation

I have a jq script like this:jq -s 'add' \< ./tmp/dispatch_03494ecb-9f72-3233-b4dc-173aa725dc24.json \< ./tmp/dispatch_03494ecb-9f72-3233-b4dc-173aa725dc24_acknowledgement.json | \ jq '{ success:...

View Article

In JQ how to safely process optionally null values

I have this JSON:[ {"alert_timestamp": "2024-10-23T08:49:08Z","odin_timestamp": "2024-10-23T08:50:10Z","alert_url": null,"comments": null,"owner": null,"updated_date": null,"clear_timestamp":...

View Article

Change the value of a path inside an existing json file

I am currently trying to adapt the paths used in one of my project to be used in any OS. Those paths are inside a JSON file (package.json), the parts I want to modify are the keys build and start...

View Article


How to convert a json response into yaml in bash

I read data from a json file with jq. I wanna append the results into a yaml file, but I dont get it working. I am quite new to shell programming. My goal is to append that "users" to an existing...

View Article

How to use miller mlr or jq to combine two JSON arrays into one array?

I used to be a jq masochist, but I discovered mlr, which seems to offer the opportunity for more (yet different) pain.I found a nice web site that allows me to issue curl commands without API keys,...

View Article

While Loop Read and JQ, use array list of column names

I want to pass a "array" to the while loop so I don't have to repeat the column namesCOLUMNS=("SOURCE_FILE" "EXIF_CONTAINER" "EXIF_CODEC" "EXIF_ENCODER")while IFS=',' read -r SOURCE_FILE EXIF_CONTAINER...

View Article

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



in jq, how to merge an array of object into 1 object with an array of values

Let's say I have this json:[ {"first": 12355,"second": "abc" }, {"first": 89010,"second": "def" }, {"first": 23423,"second": "hij" }, {"first": 23456,"second": "klm" }, {"first": 11111,"second": "nop"...

View Article
Browsing latest articles
Browse All 399 View Live