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
0
votes
1answer
17 views

Bash script for monitor the API json response

I want to monitor the below health check URL. I need generate a alert if mongodb goes to disconnected state. I wrote a bash script. Seems its still not working. Any can help on this ? Thanks When do ...
0
votes
2answers
33 views

Bashrc function case statement to import cases from JSON

I'm making a .bashrc function to get me around the system faster. I used a case statement to state where I want to go. function da() { case "$1" in home) cd ~ ;; eolas) cd /...
0
votes
1answer
23 views

JQ: convert value into nested key-value object

I am lost with an easy-looking JQ problem. Given a key-value object, I want to transform the value into a nested object with a "value"-key. I tried permutations with 'to_entries' and native output as ...
-1
votes
0answers
16 views

Filter parameters and its values from a json file

I have a JSON file coming from Alertmanager API. It consists of many key:value parameters, and I want to grep few parameters out of this JSON file. Please help. { "status":"firing", "labels":{ ...
0
votes
0answers
34 views

Running of curl processes in parallel in bash

I think post my data by curl command in terminal at the time but thousands of times to get a good turn. I wrote the following bash code: contents=$(< /Users/Andrea/Desktop/data.txt) eval "...
0
votes
0answers
30 views

Replace multiple lines in multiple files

I have the following section in more than 100 files that I want to replce: ] }, "value1": [ { "value2": { "task1": 0, "task2": 0, "a": 0, "b": 0, "c": 0 } }...
0
votes
6answers
58 views

I need to get the value after specific word

I need to get the value of "name" from this line "snapshots": [{"name":"sLVZt","user":"comment","current":"n","created":"2015-03-11 05:28:02"},{"name":"ubg9x","user":"test2",{"name":"lo3Qp","user":"...
0
votes
1answer
26 views

Trying to convert json to csv using jq

I can't seem to figure out how to use jq to turn my data into a csv. I have the following json: { "id": 2, "type": "message", "date": "2010-01-11T01:19:45", "edited": "1969-12-31T19:00:00"...
0
votes
1answer
35 views

How do I extract value of a JSON key using bash shell?

I'm using bash shell. I would like to include something in my shell script that can extract the value of a certain key in a JSON string ... davea$ json='{"id": "abc", "name": "dave"}' I tried "grep"...
3
votes
2answers
418 views

Convert JSON array into CSV

I'm looking at solutions to convert JSON to a CSV. It seems most of the solutions expect the JSON to be a single object rather than an array of objects. All the solutions I've tried from here seem to ...
0
votes
2answers
49 views

Convert large JSON file format

I'd like to know if it's possible to convert the following format {"timestamp":"1579053433","name":"1.10.207.64","value":"node-fnk.pool-1-10.dynamic.totinternet.net","type":"ptr"} {"timestamp":"...
0
votes
2answers
39 views

Add JSON objects to array using jq

My goal is to output a JSON object using jq on the output of a find command in bash. It could either be a one-line command or a bash script. I have this command which creates JSON objects from each ...
0
votes
0answers
29 views

How to echo json as string instead of bytes

I'm trying to write a json to a file: echo '{ "date":"2020-02-10 10:09:34" }' > file.json However, when I read it I need to decode it from bytes to string. I want to write it so that there is no ...
0
votes
1answer
38 views

Remove a specified word appeared only as the first word in a text file in terminal

I am working with tweeter text data in JSON format which I have stored in a text file. I am not interested in retweets and i created a parser that could extract most of the text, but somehow some ...
0
votes
1answer
23 views

Select specific all key paths and values for a specific key name in deeply nested JSON

I have a very large JSON schema that is semi structured, the nested unit structures are tagged by a key: "ObjectType" to indicate some meaningful information. I am trying to use jq to select paths of ...
0
votes
1answer
38 views

Need to convert a ssh output to json format

I have a piece of code which generates a output as chunk. TIBCO ActiveMatrix BusinessWorks version 6.4.2, hotfix 7, build V103, 2018-07-18 Connecting to the BW Agent using TIBCO ActiveSpaces (Java). ...
0
votes
2answers
67 views

Convert JSON of arrays to CSV with headers using JQ

I am getting Json as column ID and arrays - { "ObjectID": [ 0, 1, 2, 3, 4 ], "Name": [ "Apple", "Orange", "Grape", ...
1
vote
1answer
42 views

How do I filter the contents of a json array, but keep the parent with jq?

I have some JSON that looks like this: { "Vpcs": [ { "VpcId": "vpc-1", "OwnerId": "abc" }, { "VpcId": "vpc-2", "OwnerId": "def" } ] } I just want the ...
0
votes
0answers
41 views

Json to Csv with JQ

I want to convert a json file to csv file. I have a script: cat convert.sh INPUTFILE="test.json" OUTPUTFILE="outputfile-formatted.csv" jq -r '(.[0] | keys_unsorted) as $keys | $keys, map([.[ $keys[]...
0
votes
1answer
25 views

jq: globbing possible?

I have the following json output: { x0: { scores: { small, human readable }, payload: { huge data } } { x1: ... } { x2: ... } ... { xn: ... } What I would like to do is, when I finish generating ...
2
votes
2answers
71 views

Extracting a json value from bash shell using awk without having to resort to both awk and sed

The aws command returns a json string to stdout inside a bash shell. $ aws ssm get-parameter --name /mysite/dev/email { "Parameter": { "Name": "/mysite/dev/email", "Type": "...
1
vote
1answer
356 views

Parsing JSON data from a curl API request

I'm using Shodan's API https://developer.shodan.io/api to get my current network alerts. I want to parse out the id for the alerts with jq. The curl request is curl -X GET -i https://api.shodan.io/...
1
vote
1answer
88 views

JQ - add element to array and return full json

I'm trying to add an element to an array like this: jq --arg root "arn:aws:iam::$ACCOUNT_ID:root" \ '.Statement[] | select(.Sid=="Allow use of the key") \ | .Principal.AWS ...
3
votes
3answers
73 views

How to parse Stdout as a mix of CSV and JSON?

I'm currently working on a class that has us submit our code to an auto-grader and then returns our results. The format it returns is kind of hard to visually parse, so I would like to write a script ...
4
votes
1answer
90 views

How to print path and key values of JSON file

I would like to print each path and value of a json file with included key values line by line. Given the following json and jq, is it also possible to add the values for each line? If not using jq is ...
-1
votes
1answer
46 views

looping through JSON array in shell script using for loop

Below is the curl command output, need script or command to print "doc_count" less than 10 and save the "key" in output.txt file. { "took": 117, "timed_out": false, "_shards": { "total": ...
0
votes
2answers
72 views

How to filter only particular lines from a file?

I have a file which has following lines. I just was to see IP address which is the first line, second line country only once and the score line only once but the score line should be the highest value ...
2
votes
1answer
115 views

jq: how to print one line per sub-object values, repeating top level value with sub-objects value

I'm trying to print only certain values from a json (one line per sub-object) repeating one value from the top object on each line. Sample input: [ { "name": "level1Name", "lv1id"...
0
votes
1answer
55 views

how to separate single json file to pieces of json files

We have the following json ( example 1 ) example 1 more file.json { "version": 1, "partitions": [ { "topic": "list_of_cars", "partition": 2, "replicas": [ 1003, ...
0
votes
0answers
15 views

Attempting to write PHP array to file in Linux PHP interactive shell produces Uncaught Error and empty file

After executing the following commands: [root@server test]# php -v PHP 7.2.25 (cli) (built: Dec 17 2019 22:57:09) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-...
4
votes
1answer
525 views

How to drop decimal place on numbers in a JSON array?

What shell command in a bash script could be issued to efficiently strip all the decimal places from the numbers in a JSON file such as this: [ { "IMSKU": "1000001", ...
1
vote
3answers
351 views

Replace third word in double quotes from file

This is the json file that we want to edit Example 1 { "topics": [{"topic": "hfgt_kejd_tdsfd”}], "version": 1 } Example 2 { "topics": [{"topic": "hfgt_kj_fsrfdfd”}], "version": 1 } We ...
0
votes
1answer
46 views

Variable not resolving in multi line string assignment

I'm trying to create a shell script which gives a Json block which is used further. The Json block consists of the dynamic components assigned as variables. Below is the code snippet failCount=$(cat ...
0
votes
1answer
278 views

How to iterate over JSON object collection (not array) in Perl?

I'm learning Perl. I have been able to successfully iterate over a JSON collection when the objects were contained in an array. However, I cannot understand how to work with JSON data where the ...
0
votes
1answer
176 views

Read a json file and run a command in Bash

I wanna block a mac address which downloaded value is over "20480": The json file: { "client_length": 3, "clients": { "ac:07:5f:77:40:e9": { "id": 1, "ip": "192.168.5.40", ...
9
votes
4answers
699 views

Command to keep only a portion of JSON data from each line?

I have test.json file with different lengths of rows. Some fictitious example: { "a" : 123, "b": "sd", "c": 45, "d": 1, "e": "" } { "a": 5, "b": "bfgg", "c": "x4c", "d": 31, "e": "" } I want to just ...
0
votes
1answer
56 views

How can I export ZSH history into JSON?

I'd like to export my ZSH history with timestamps as JSON output. How can I achieve this? Do I need to manually parse the output from something like history -E?
0
votes
2answers
166 views

Import variable into jq

We need to use the variable $domain_name instead of the hyb.com string in the following jq command: jq --argjson IDS '['"$(seq -s, -f'"car%02.0f_hyb.com"' 11)"']' ' .mazda |= $IDS ' file.json When ...
0
votes
1answer
93 views

jq + update json file and append name according to ID number

We want to edit the json file according to the following rule We need to generate the name car0X_hyb.com - under mazda string ( while X is the ID number ) we need to update the json file on our ...
0
votes
2answers
379 views

jq filter for only 'null' values

I have a json file with a load of AWS CloudWatch logs (generated from a CLI command). I'm trying to use jq to only return values for entries that don't have a 'retentionInDays' field. I have the ...
0
votes
2answers
666 views

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

I'm trying to write a bash script with make s curl call and get a json document back. The json document has a key called access_token and I need to extract the value of this field. This is my json ...
0
votes
3answers
83 views

Parse value from different JSON strings (No jq)

I'm using bash script that needs to read the JSON output and parse a value from different JSON variables or strings. Here's the sample output. It needs to read the value next to the Content or from ...
1
vote
1answer
45 views

How to JSON-escape input?

I am trying to come up with a tool what for sending data up to a github gist via the API. The problem is the github api takes the gist content as a single line with all escape sequences written out ...
-1
votes
1answer
37 views

How to get just two items of a json like file

I'm trying to parse the Sublime Text 3 session file: Session.sublime_session. It consist of what look like JSON formatted stuff. Using: cat Session.sublime_session | grep -A13 "\"file\":" I can ...
2
votes
2answers
154 views

Printing only the value and excluding null

I'm trying to print the json output using jq, But I'm getting null How can I print only access_key and secret_key, but not null? $ cat sample.json | jq '.' { "access_key": "...
0
votes
0answers
52 views

How do I use bash script to parse a JSON and run related commands according to the parsed results? [duplicate]

I have a JSON file (array) like this: [ {"name":"Joe","age":36}, {"name":"John","age":14}, {"name":"Linda","age":62} ] And I want to parse it in shell, analyzing every item in the array, then ...
1
vote
1answer
209 views

How to construct a JSON object from multi-word (space-separated) bash variables?

I have a small bash script that uses jq to construct a JSON object from user input. Unfortunately, I am unable to convince jq to accept a multi word variable as a value to one of its keys. Here is an ...
0
votes
0answers
197 views

Help parsing JSON stream into Python with BASH and jq

I'm decent when it comes to writing python code but BASH is fairly new to me and I'd like some guidance on picking a high level approach to achieving my goal of reading sensor data from a live ...
-2
votes
1answer
32 views

JSON_TABLE problem

I have a JSON structured like that ... { "market_order_line_details__c":[ { "PriceItem__r.Catalog_Item__r.Parent_Catalog_Item__r.Parent_Catalog_Item__r.Calendar__r":{ "...
0
votes
2answers
621 views

Using jq to create comma separated list fields in JSON array

I am trying to use jq to join the values inside a JSON array into a single line comma separated list. (Without trailing comma) { "hardware": [ "abc", "def", "ghi" ] } To create "abc,...

1
2 3 4 5 6