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
2answers
48 views

Using sed to extract number from json

I'm struggling to use a single sed command to extract a number from some json on Linux. Given the following block: { "key1": 100, "key2": 200, } I'd like the output to be 100 in the above ...
6
votes
2answers
14k views

jq print key and value for all in sub-object

I found this Q/A with the solution to print all the keys in an object: jq -r 'keys[] as $k | "\($k), \(.[$k] | .ip)"' In my case I want to perform the above but on a sub-object: jq -r '....
1
vote
3answers
54 views

How to retrieve specific cpu, memory and interface statistics only

There is requirement to collect only specific stats like %idle, memfree, available, pmemused etc. I further have to convert the output to a json string and consume it. Is there any UNIX tool which ...
1
vote
2answers
34 views

How to grep multiple lines?

Grep understands this : curl https://api.coinmarketcap.com/v1/ticker/ | grep "clipper-coin" But not this : curl https://api.coinmarketcap.com/v1/ticker/ | grep "{*clipper-coin*}" The output I ...
1
vote
2answers
448 views

Passing variable to jq to edit a json file

I am trying to pass a variable into jq like this '.Linux.date.$var' so far I have tried quoting them by name which is working fine. But I want to use variable to call them. I have this, which is ...
0
votes
3answers
109 views

Parse a string in bash script

I reviewed other answers but couldn't get a proper explanation of how to do this. I have a string variable called id such that id='{"name":"john"}'. How can I get 2 variables out of this string like- ...
0
votes
5answers
74 views

Grep a string from json data

I got json data in the following format, I prefer to use use sed or awk, jq is not supported, grep -o is not supported on solaris box [{"FRUIT":"APPLE","CAR":"FORESTER","COMPANY":"SUBARU","MAKE":"...
0
votes
2answers
24 views

Ubuntu - How do I pass JSON string to herestring?

Update I noticed that I am able to pass JSON with this command command -j /dev/stdin <<< '{"key":"value"}' However, it does not work if I call it through SSH. ssh {target} 'command -j /...
1
vote
1answer
42 views

Handling null (empty array) while converting json to csv with jq?

When trying to convert json to csv, I get an error about null with the following jq query: printf "[]" | jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $...
6
votes
1answer
4k views

jq - print “-” for null values

input json: { "id": "3885", "login": "050111", "lastLoginTime": 1529730115000, "lastLoginFrom": "192.168.66.230" } { "id": "3898", "login": "050112", "lastLoginTime": null, "...
2
votes
1answer
24 views

What is the difference between vertical pipe and juxtaposition in JQ?

My program returns JSON into stdout and it is an object with operations field, which contains a list of operations. Each operation contains fields including id fields, for example: { "operations":...
1
vote
2answers
48 views

Pass variable within json payload in shell script

In the following scenario, which is the way to pass ${MY_ENV_VAR} in the payload? I will have to escape: a) the single quotes of the payload b) the double quotes of the value of the text json ...
0
votes
1answer
66 views

Cronjob fetching JSON with cURL. Check if response isn't empty before writing to file

I'm running Ubuntu and got a simple cronjob fetching a remote JSON-file and (over)writing it to the server. */15 * * * * /usr/bin/curl -m 120 -s https://path/to/remote/json.json > /store/json/here....
0
votes
1answer
34 views

CSV to NESTED JSON

I need to convert a CSV file to a JSON output, I'm using the csvtojason library from https://www.npmjs.com/package/csvtojson, csv File: mode,device,stb,data,data1,data2,data3,data4 modelo1,device1,...
0
votes
1answer
31 views

trim using sed to get the exact value from curl

I'm getting this string data from curl command {"password": [["passwordreal", "2035/01/01 00:00"]], "user": "user1", "address": "kobebkokoko.net"} How do I get passwordreal using sed? Example, ...
0
votes
0answers
42 views

Add bash variable as JSON key and value into object

I have a JSON array of objects like so . [ { "id" : "tmp1387816934708382026", "owner" : "john", "x11-display" : ":5", "x11-authority" : "/run/user/john/dcv/tmp1387816934708382026....
0
votes
2answers
177 views

How to write routine to escape double quotes in a JSON string [closed]

I have to be efficient so I can't use tools like jq which loads up a big binary executable. I just want to escape double quotes in a string so it's safe for JSON. This isn't good enough: echo ' bad \"...
3
votes
3answers
3k views

Sanitize Json for sending with Curl

I have to send a POST request to some service with json payload, and it includes some user input. That input variable needs to be Json-encoded to prevent injection attacks. Code example that ...
0
votes
1answer
62 views

If/else within a grep statement

I am trying to find all instances of "type":"FollowEvent", and then within those instances, if the string "actor": is not followed by {, then capture the string enclosed in " that comes immediately ...
1
vote
2answers
2k views

Get values for a given key and its parent with jq

I've got a JSON array like so: { "1": { "available_memory": 1086419656.0, "available_memory_no_overbooking": 1086419656.0, "conns": 1.0 }, "2": { "available_memory": 108641236.0,...
0
votes
1answer
115 views

Get parent nodes by child node selector with jq

I'm trying to parse json with jq { "xxx": { "aliases": { "business_event": { "is_write_index": true } }, "mappings": { "...
8
votes
3answers
22k views

Setting jq output to a Bash Variable

I'm using curl to get JSON back from a rest api like this: content=$(curl -s -X GET -H "Header:Value" http://127.0.0.1:8200/etc) echo "${content}"| jq -r '.data.value' which produces the value I ...
0
votes
1answer
55 views

Rename files based on JSON content using jq

I need to make a shell script that uses jq to rename below mp4 file(s). (could have use jasonpipe but didn't know how to install it on mac) File Dowloaded: title1-1000221327.mp4 title1-1000221327....
1
vote
1answer
289 views

Convert json file to a “key-path” with the resulting value at the end of each “key-path”

I have a large and relatively complex json configuration file that I want to search for keys and/or values using simple tools like "grep". When I 'grep' the file I would like to have in the output ...
0
votes
0answers
96 views

iproute2 - ip addr json import

I can get a json export from my network configuration with following command: ip --json addr show result: [ { "ifindex": 1, "ifname": "lo", "flags": [ "LOOPBACK", "UP", ...
0
votes
4answers
145 views

sed command to replace a value in a config file

I'm working on an automation script and I need to change the value in a config file. The config file that I'm trying to edit has a line like this (including the spaces before): "peer-port": 23456,...
1
vote
2answers
322 views

Overcoming newlines with grep -o

I have a file similar to such. SampleOutput { "1": { "state": "RUNNING", "stats": { "name": "some-file", "uris": [ "some-example.com" ], ...
1
vote
2answers
5k views

Convert text file to JSON

Using curl, I get some statistical information from my TP-Link router. I put that information to a text file. However, I need this info in JSON format so that I can use it elsewhere. The format of the ...
42
votes
7answers
161k views

How do I count the number of occurrences of a word in a text file with the command line?

I have a large JSON file that is on one line, and I want to use the command line to be able to count the number of occurrences of a word in the file. How can I do that?
5
votes
5answers
6k views

Is there a CLI tool that would prettify a JSON string

On my host I enter the following, which returns a bunch of information which isn't particularly easy to read at the CLI. echo $ENV_VAR | base64 --decode Is there a way to format it? This is a ...
1
vote
1answer
531 views

jq (command-line JSON processor) merge multiple JSON strings from STDIN

I am trying to merge two different JSON strings from STDIN (using pipe, not files) using jq command. Here's the command trying: curl ipinfo.io api.ipify.org/?format=json 2>/dev/null | jq -s ...
1
vote
1answer
78 views

Convert JSON with raw characters in string

Had a problem with a tool that was generating illegal JSON. Some of the JSON strings contained characters in the range 00-1f. So I wanted to convert these characters to correctly escaped valued \...
1
vote
2answers
660 views

Loop into JSON Array in Bash Script

I make a curl request to an API and get a json return with jq. The result { "errors": [], "metadata": { "clientTransactionId": "", "serverTransactionId": "20190318164551347" }, "...
2
votes
0answers
95 views

JSON -> csv creating header line and padding header if found empty field

I have a programme in bash that get JSONline files with several million of these object per line (See source) { "company_number": "09626947", "data": { "address": { "address_line_1": "...
9
votes
4answers
2k views

Wrap all numerics in JSON with quotes

There are JSON data which contains some numeric values. How to convert all numerics to strings? (wrap with quotes) Example: { "id":1, "customer":"user", "plate":"BMT-216-A", ...
6
votes
6answers
6k views

How to loop through json file?

I have a below json file and I want to get the hostId, only if the name contains some specific value. I want to use shell script to achieve this. { "items" : [ { "name" : "first-block-...
0
votes
1answer
2k views

curl with Umlaut causes “JSON parse error: Invalid UTF-8 middle byte 0x22” [duplicate]

I'm running below curl command from the command line (Git Bash on Windows) or as part of a Bash Script. curl -s -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d "{\"...
1
vote
2answers
47 views

How could I (painlessly) split or reverse “Last, First” within a record in Miller?

I have a tab-delimited file where one of the columns is in the format "LastName, FirstName". What I want to do is split that record out into two separate columns, last, and first, use cut or some ...
-3
votes
3answers
1k views

script to translate xml to json

I have 5000 questions in txt file like this: <quiz> <que>The question her</que> <ca>text</ca> <ia>text</ia> <ia>text<...
-1
votes
2answers
321 views

Using filter condition in python -mjson.tool command

Can I use a filter condition in python -mjson.tool command to select objects which has specific attributes? For example, I have a sample.json file with for objects out of which two has an attribute "...
1
vote
2answers
77 views

Update file with multiple values automatically

I have a hosted zone and record set that route to multiple addresses. I'd like to update the record set with adding or removing one IP address in the list. Unfortunately, AWS CLI doesn't provide the ...
1
vote
2answers
168 views

How convert bash output to JSON with key {#PROCNAME}?

I try get JSON with top 5 process by memory. This JSON i want send to Zabbix and draw top 5 process by memory. I get top 5 process by memory by command: ps axho comm --sort -rss | head -5 node ...
-2
votes
4answers
104 views

Json. How to add a sentence after :

The following is an extroct from a json file, that I have: }, { "name": "asdasd", "script": "dsad.js", "merge_logs": ture, "error_file": "/ofghfghgfh.log", "out_file": "/...
0
votes
2answers
197 views

How to use grep multiple pattern and remove the first pattern [closed]

The code that I've tried is not getting the exact output that I want. This is my code that I've tried: curl -s --request GET \ http://10.10.5.242/api/v1/incidents \ -H "Content-Type: ...
1
vote
1answer
513 views

Combining youtube-dl and VLC without a pipe

youtube-dl -o - <webpage> | vlc - shows a video in VLC. However, the video is piped (through something like fd://0), which inhibits the possibility to jump forwards/backwards. However, youtube-...
0
votes
3answers
197 views

jq is not appending json file

I have a json file like this: { "active": "secure", "secure": { "nodetype": "secure", "nodeid": null, "servers": [ "ts2.na", "ts1.na", "ts3.na" ], "stakeaddr": null, "email": ...
11
votes
4answers
29k views

parse one field from an JSON array into bash array

I have a JSON output that contains a list of objects stored in a variable. (I may not be phrasing that right) [ { "item1": "value1", "item2": "value2", "sub items": [ { "...
1
vote
1answer
67 views

Script to modify the structure of a JSON file

I'm looking for a script that can solve a problem I'm having with a JSON file. The thing is that an API is delivering this file to me: { "device 1":{ "general_data":{ "descriptions":...
0
votes
1answer
268 views

make json from SQL query output

I have this query: select hostname,size from tableinfo output is like this: hostname size ------------------------- ----------- host1 28 host2 ...
0
votes
1answer
141 views

How to get value with JQ (JSON) [closed]

I want to get the value of result.data (but it gives me null) can somebody explain me how targeting in the json below works. Do not understand it. { "ActTime" : 1547809207, "AstrTwilightEnd" : "...