Questions tagged [json]

JSON (JavaScript Object Notation) is a lightweight data representation format that resembles JavaScript source and that is can be easily red by machines and edited by humans with some effort.

Filter by
Sorted by
Tagged with
4 votes
3 answers
147 views

How to process JSON with strings containing invalid UTF-8

A large (and growing) number of utilities on Unix-like systems seem to be choosing the JSON format for data interchange¹, even though JSON strings cannot directly represent arbitrary file paths, ...
Stéphane Chazelas's user avatar
1 vote
1 answer
28 views

Convert csv out of json in new coloumn

The below is my json code [ { "kind": "user", "version": "v2", "metadata": { "name": "person1" }, "...
code userit's user avatar
0 votes
2 answers
34 views

Is it possible to read the very first value of the JSON response

Here is a JSON response I am receiving from a server: { "GoUZm0F3r-rZ0tItdurVfPLCAfBGrnvF32": { "entityId": "GoUZm0F3r-rZ0tItdurVfPLCAfBGrnvF32", &...
Ashish's user avatar
  • 1
0 votes
2 answers
61 views

Getting Error "{"errorMessages":["There was an error parsing JSON. Check that your request body is valid."]}

curl --request POST \ --url 'https://bankofloyal.atlassian.net/rest/api/2/issue' \ --user [email protected]:$JIRA_TOKEN \ --header 'Accept: application/json' \ ...
Abhishek Kumar's user avatar
0 votes
1 answer
45 views

How do I refer to attributes with dollar signs in the name in jq?

I have some JSON: { "Data": { "$id": "1", "voters": { "$id": "2", "$values": [ { "$id&...
Joel Breazeale's user avatar
0 votes
1 answer
29 views

Force Patch character differences to a file

Hello, I have an englishStrings.json file and when I make new edits/ additions to it, I need to copy the new changes to all the other language string.json files. Before making any changes to ...
Freezer Fridge's user avatar
-1 votes
1 answer
46 views

Add Array of Object in JSON with condition

I have system that output multiple types of JSON file with data Is there any chance to implement above three conditions using JQ package? I am exploring map, arg and argjson command. But I am having ...
infotechsups's user avatar
2 votes
2 answers
150 views

Convert json to csv with headers in jq

Is it possible to convert this json: [ { "bytes": 276697, "checked": false }, { "bytes": 276697, "checked": false ...
Daniel Krajnik's user avatar
0 votes
1 answer
56 views

Forcing miller to read data as string in conversion to JSON

In the following MWE echo x="1e2" | mlr --ojson cat my intention is for miller to generate a one-element JSON array containing the object {"x": "1e2"} The object ...
Marcos's user avatar
  • 103
8 votes
4 answers
791 views

How to format a JSON string as a table using jq?

I need to convert a JSON string using jq, as shown below, into a table format for displaying the output in the terminal. { "results": [ [ { "field": "@...
Velin Budinov's user avatar
0 votes
2 answers
138 views

Using jq to parse invalid JSON?

Can jq parse invalid JSON such as this?: [2023.06.07-21.58.47] StatManagerLog: { "RoundState": { "State": "Starting", "Timestamp": "...
swat37's user avatar
  • 3
0 votes
2 answers
140 views

Add new key to JSON file, with value equal to the length of other key's value

I'm adjusting a JSON file that holds a large number of objects. Here are the first three objects as an example: {"id":"0704.0001","submitter":"Pavel Nadolsky",&...
A.Co's user avatar
  • 3
0 votes
1 answer
136 views

Unable to resolve parameter inside json

I'm using a curl command inside a script (edm.ksh) to retrieve some data from an API, it requires a password in a JSON like {"password":"myPassword"}. Now, myPassword is not ...
Pratik Khobragade's user avatar
1 vote
1 answer
462 views

How to keep one specific key from a nested json object?

I have the following config.json file: { "auths": { "reg1.io": { "auth": "...
Franck's user avatar
  • 13
2 votes
2 answers
111 views

How can I select only successful values from leakcheck output?

I have these results that came from leakcheck. How do I properly exclude "false" results and still include the email using bash [email protected] {"success":false,"error":&...
noobwithskillissue's user avatar
7 votes
4 answers
704 views

How to gather values into array by keys?

Given input in entries format, possibly with duplicated keys, e.g. [ {"key": "a", "value": 0}, {"key": "a", "value": 1}, {"key&...
友人A's user avatar
  • 173
4 votes
4 answers
1k views

How can I edit this JSON file with bash script and jq

I have config.json file with the following content: [{ "host0": "11.11.11.11", "host1": "22.22.22.22", "host2": "33.33.33.33", "...
Trinitron's user avatar
-1 votes
1 answer
1k views

How to send multiline data in curl body within bash script?

I am trying to send multi-line comment in the curl body from bash script. Below is my curl invocation. #!/bin/bash temp="This is sample data: 2019/05/21 03:33:04 This is 2nd sample data: #...
Preeti 's user avatar
  • 203
0 votes
3 answers
120 views

How to fetch the value inside a json file for linux

I have an data which i am trying to fetch various method and the result is [ "created:Alpha;DateCreated:12/12/2022;TicketNo:XXXX_XXX;ProductName:websphere;OStype:Linux" ] I want to fetch ...
raj krish's user avatar
0 votes
1 answer
420 views

Get parent of all matching value in JSON using jq

I am new to jq and I have a scenario to get the parent(at a particular level) of any matching value in the json file. Below is the sample data. { "DevOps": { "us-east-1"...
Murali SP's user avatar
0 votes
2 answers
2k views

Expand variable in the JSON payload of a curl command

I have a shell script that sends a post request with curl. #!/bin/sh NEXT_JOB_COMMANDS='["sleep", "200s"]' STATUS="successful" if [ "$STATUS" = "...
ar-siddiqui's user avatar
0 votes
3 answers
77 views

How to print the content between the third and the forth double quotation marks

I have some logs from a web service on a Linux machine. The logs look like this: {"log":"[2023-03-09T06:39:10.669Z] \"GET /server/prod?blank=true HTTP/1.1\" 200 - 0 874 1 1 \&...
Yves's user avatar
  • 3,181
5 votes
4 answers
1k views

Generating JSON in a shell script

I need to generate JSON output as below: [{ "Service": "service1-name", "AWS Account": "service1-dev", "AD Accounts": { "APP-...
Marco Ferrara's user avatar
5 votes
2 answers
3k views

How to add a key value pair into a JSON file with JQ?

I have the following JSON file located at /tmp/target.json: { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", ... } } I want to add ...
CaTx's user avatar
  • 161
0 votes
2 answers
176 views

Extract value from broken JSON output in Shell

Once I list the backup files from a server, It throws me the output as follows: { "backupFiles": [ "XYZ_Backup_2.0.0.0-417_2022_08_14_12_10.gz", "...
user560884's user avatar
1 vote
2 answers
2k views

get key and value from json in array with check

I had a json [ { "name": "type1", "type": "string", "values": { "set1": "dataA1", ...
decipher's user avatar
  • 162
0 votes
2 answers
1k views

Get json value using regex in linux bash

I have a json file file.json like this: { "abc": "123", "def": 456, "ghi": 789 } I am trying to get value of all the keys using regex in bash terminal. ...
mmk's user avatar
  • 111
1 vote
2 answers
3k views

Create a Json using bash script

I have a file which has list of cidr's. How can I create a big json with below format using bash script With single CIDR [{"source":"1.1.1.0/32","protocol":"17",...
ph3ro's user avatar
  • 378
0 votes
1 answer
109 views

How do I find and replace something AFTER a specific term in a terminal output

I need to run blkid and copy a specific UUID after a specific known partition name. Then, I need to paste this into an exists config file, replacing a UUID that it's already there (parent_device_uuid)....
Capybara_Overdose's user avatar
0 votes
1 answer
2k views

jq: error (at input.json:45): Cannot index array with string "value"

I try to convert my .json files to .csv with jq. I'm getting cannot index array with string value on all my values. .json { "organic_data": [ { "description": "...
pwrsheller's user avatar
2 votes
2 answers
2k views

How to parse and add content to json using bash?

I am following the ideas from the stackexchange articles below here to select and delete an element Delete Element here to append an element: Add New Element but I am having problems with quotes ...
Daniel Ferreira Castro's user avatar
2 votes
1 answer
3k views

Jq contains query with a variable containing spaces

I've been having an issue with searching a json field that has spaces it in it with a variable containing the search term that also has spaces in it. I've been using the contains search but I'm not ...
user avatar
0 votes
1 answer
565 views

Parsing JSON output to variable in bash using jq filters

I have a query like this: curl -s \ -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $API_TOKEN" \ --data "$(echo $PAYLOAD)" \ https://myapi/...
Jeff Sani's user avatar
0 votes
1 answer
117 views

Find and replace everything inside bracket using unix shell - several lines

I need to find and replace a big part of a json file using shell. For exemple I have this file : { "Balise1": true, "Balise2": true, "OtherThingEnabled": false, ...
Raph04's user avatar
  • 3
2 votes
1 answer
363 views

Add Bash Variable as key for JSON object

I am running a command that is pulling json from kubectl and I need to take that json and input it into another json array. Currently, my command looks like this kubectl get ingress -o json | jq --arg ...
Victor Gonyo's user avatar
2 votes
0 answers
175 views

How to combine two JSON objects using jq

I have two files: kube-apiserver.json { "apiVersion": "v1", "kind": "Pod", "metadata": { [...] }, "spec": { ...
landocalrissian's user avatar
2 votes
1 answer
1k views

How to merge multiple json object into one json array in shell

I have a requirement to read some fields of json data from a file to compose a new json list. The file is generated by reading data from multiple servers via pssh # pssh_result.txt [1] 14:44:51 [...
moluzhui's user avatar
  • 123
0 votes
1 answer
356 views

How to extract data from a JSON file into a variable

I have the following json format, basically it is a huge file with several of such entries. [ { "id": "kslhe6em", "version": "R7.8.0.00_BNK&...
Manoj Kumar's user avatar
1 vote
1 answer
221 views

Sum up entries from json and save it in a variable

I have the below json file [ { "n_id": 1, "n_key": "sdfvnifughsdfvnsdfvnsd", "entries": 7 }, { "n_id": 2, ...
ph3ro's user avatar
  • 378
0 votes
1 answer
724 views

AWS CLI output append to json file

I have a sample.json with the content below : {key:value} I want the AWS secrets CLI command output (secretstring json object) { user:name, pass:word } to be appended to my JSON file above so that ...
user2573747's user avatar
1 vote
1 answer
400 views

Parse a multidimensional json array using bash

I'd like to iterate over a multidimensional json array in bash but haven't found a solution. Here is what the multidimensional array would look like: { "FILES": [ [ "file1....
hickersonjl's user avatar
0 votes
1 answer
3k views

How to dynamically find a value of a key-value in json in bash script

I'm new to bash scripting. I am iterating over a list and want to get the value from a JSON object. I've tried all 3 of these and am getting a jq: 1 compile error What is the proper syntax? for key in ...
PartOfTheOhana's user avatar
0 votes
1 answer
126 views

Convert terminal tables into csv or json

Does a tool exist to convert tables on the command line like snap list or flatpak list into csv or json ouput. I imagine it like this: <name> "snap list" --csv
Sebastian's user avatar
1 vote
1 answer
2k views

jq nested reduce/grouping of JSON data

I'm working on a large JSON dataset (1GB+) and need to merge similar array objects, then merge their nested similar objects. Starting with, I have rows such as: [{"item": "item1", &...
jqmadness's user avatar
0 votes
2 answers
604 views

Save a json value as variable

I am getting the below output from a command. { "data": { "access-type": "ObjectRead", "access-uri": "/p/u4yRbnS_Yv29ivICXNWz-...
ph3ro's user avatar
  • 378
4 votes
3 answers
1k views

Prepend string to each key in JSON file

I have a JSON file I'm reading into a bash script and would like to prepend a fixed string to each key. json_file: {"key_1": 12, "key_2": 34, "key_3": 56} What's the ...
user546158's user avatar
2 votes
1 answer
152 views

How can I get value from string?

I have this curl output below: { "code": "Ok", "routes": [{ "geometry": "mlbj@qsp}VlEi@hAvHRCiKyr@gBkK`MmBN`AcC^QaA}GbAm@PRx@lDzUu@L?V", "legs": [{ "steps": [], ...
genesis lubrigas's user avatar
3 votes
1 answer
8k views

JSON: Extract and print both key and value pair for value matching pattern

JSON: "{ "a": "https://is2-ssl.com/", "b": "https://a5.-ssl.com/", "type": "response", "c": [ { "...
King's user avatar
  • 43
2 votes
2 answers
530 views

Text file to JSON

I have a text file of IP:PORT, like for example 1.1.1.1:1919 2.2.2.2:111 1.1.1.1:987 I need to use them in a script which has a JSON format: async def main(loop): servers = [{ "...
ph3ro's user avatar
  • 378
2 votes
1 answer
3k views

Convert comma separated string into json array

I have the following string in bash "3.8,3.9,3.10" Is there a way using shell to convert it into a json array, i.e. ["3.8", "3.9", "3.10"]
pkaramol's user avatar
  • 2,637

1
2 3 4 5
11