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.

learn more… | top users | synonyms

1
vote
1answer
24 views

How to POST 'shell output' as JSON data with Curl

I got the following command: curl -H 'Content-Type: application/json' -X POST -d '{"host": "'$(hostname)'"}' http://sitename.com/update.php Which works as expected, but if I try to send uptime ...
0
votes
1answer
39 views

Remove duplicate lines from multiple json files while preserving file structure

I have a folder with thousands of json files. The contents of each folder look something like this: file.1424-417982.json file.1424-417995.json file.1424-418013.json file.1424-418015.json (etc.) ...
1
vote
1answer
34 views

What are the consequences of having many files in a directory in an ext4 filesystem?

My task is to store a list of JSONs on disk (without using any database) and I have these options: Store them in a single, large file. Store them in separate files, keyed by their IDs. Personally I ...
-1
votes
1answer
37 views

Append value as parameter to shell script

I found the value of a response (curl) with sed and now i need some help to take the value that i printed in a file and to use it in another substring in the same .sh script This is the response of ...
0
votes
2answers
55 views

Extract UUID value from JSON returned from HTTP reply

I am trying to make a little script in shellscript that takes one serviceUuid from a response and use it. I just print the server response on a file called final.txt Now i need to extract the value ...
1
vote
1answer
45 views

send json via rsyslog to elasticsearch

in our company we need aggregate services statistics for some reason we decide to use rsyslogd to send applications statistics (json format) to elasticsearch system directly (this tutorial). but we ...
1
vote
1answer
27 views

Echoing text and executing a command with jq

I have a command that spews json to stdout like so: foo inf --db { "Name": "A rose by any any other", "Config": { "DBHost": "abc.efg.us-east-1.rds.amazonaws.com", "DBName": ...
0
votes
1answer
33 views

Specifying a config file for a server setup script

I am trying to write a server configuration script. I want to make this as flexible as possible - which means some configuration options might need to be nested. A sample: options: { key1: ...
-1
votes
1answer
42 views

Replace a value in a file, in a certain context, with an operation result

I have an array of JSON object with inside local urls and speed parameters like [{server:"192.168.0.100", speed:34}, {server:"192.168.0.130", speed:52},...] I need to update the speed value for each ...
1
vote
1answer
34 views

Wildcard in jq with comparatives

Piping in some json, I want to be able to add a wildcard to the comparative, so: curl example.com/json | jq 'select(.[].properties.type == "dev*")' So it would print out anything with a type that ...
1
vote
2answers
41 views

grab text out of vtt file

vtt files look like this: WEBVTT 1 00:00:00.096 --> 00:00:05.047 you're the four functions if you would of management first of all you have the planning 2 00:00:06.002 --> 00:00:10.079 the ...
0
votes
1answer
34 views

parse Mongodb logs with syslog-ng

I'm receiving a lot of Mongodb logs with my Syslog-ng. below is the sample of logs parsed and stored like this: 2016-10-18 19:01:08 f:local1.p:info h:10.133.126.81 prog:sharmongo-log m:sharmongo-log ...
1
vote
4answers
49 views

Separate two values from a large of text, while each of readings separated by a blank line

I've got a peace of large text file with readings like below, name=ABC class=3 age=7 roll_no=41 name=XYZ class=4 age=9 roll_no=23 So, how can I separate each name with their respective age and ...
3
votes
2answers
50 views

Extract a value from command output and use the value as a parameter to a subsequent command

Hi there I am trying to have curl -v --request POST https://example.com --data-urlencode "username=usr]” --data-urlencode "password=[pass]” pass the output to the [TOKEN] field in here: curl -D - --...
0
votes
2answers
75 views

Bash variable substitution in a JSON string

I'm trying to create a JSON in BASH where one of the fields is based on the result of an earlier command BIN=$(cat next_entry) OUTDIR="/tmp/cpupower/${BIN}" echo $OUTDIR JSON="'"'{"hostname": "...
2
votes
3answers
130 views

Merge jq output into a comma seperated string [duplicate]

I am trying to curl some URL which return json file, then I want to parse hosts from it and create a comma separated string. I have the first part working curl -s -u "admin:admin" -H "X-Requested-...
1
vote
2answers
43 views

Overcoming newlines with grep -o

I'm a little new to regex and need a little help. I have a file similar to such. SampleOutput { "1": { "state": "RUNNING", "stats": { "name": "some-file", "uris"...
2
votes
0answers
16 views

How to render geojson locally

I have some visualizations which consists of data in the GeoJSON format. I would like to render the features to a png file. There are some sites which provide this functionality. I have for example ...
1
vote
1answer
61 views

How to format streaming JSON output from Node.js?

I have a Node.js server that uses JSON logging. When running the server locally, it outputs log entries as JSON objects which are quite tedious to read. I would like to pipe the output through a ...
0
votes
1answer
50 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 ...
1
vote
2answers
81 views

Where can I find shell script for parse JSON on busybox?

I have an IP camera with armv5tejl architecture. There I have busybox. I have to be able to parse JSON responses from curl. The problem is that I don't have programs like: jq, jshon, jsawk... It is ...
0
votes
2answers
85 views

Extract the value part from key-value pair separated by colon in Linux

I need to fetch arn:aws:sns:us-west-2:596873354795:demo from the below content in a file using sed command. What would be the command? Sample file: { "TopicArn": "arn:aws:sns:us-west-2:...
0
votes
1answer
44 views

upload ssh key on github from command line

I have found a way to upload an SSH key to my GitHub account with command line, but there is small problem. I am able to do this with following command: curl -u "user:pass" --data '{"title":"test-...
0
votes
3answers
75 views

How do I find the string after a regexp on a single line of text?

I have a text file containing a very long line of JSON data and I need to extract the value of some field.  I realize the easiest way to do this would be to use jq or grep -o; however, I am on a ...
3
votes
4answers
230 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-...
3
votes
1answer
114 views

Rename files based on JSON content

I have two sets of files; file1.txt file1.json file2.txt file2.json file3.txt file3.json ... fileN.txt fileN.json json files contain the following format: {"ago": "59 sec ago", "...
2
votes
1answer
247 views

can't find documentation on json.tool [closed]

I can find scattered articles online that use json.tool to produce pretty python, but no clear documentation on usage. I checked docs.python. but there is no formal documentation of json.tool. I ...
1
vote
1answer
62 views

JSON with variable key in bash

In the bash script below, I have JSON object and need to have key hostname with random name, like host-$NAME (i.e. host-1, host-3). How to do it ? #!/bin/bash NAME=($(( ( RANDOM % 10 ) + 1 ))) ...
1
vote
3answers
769 views

POST json data with cURL from a while loop - bash shell

I have a JSON output from which I need to extract an ID and Iterate through them and send multiple request to API execute REST API with curl. For example: This is how the JSON output looks like: { ...
1
vote
3answers
54 views

How can I parse JSON to test the string value of a nested key?

For example, here is my program's output (bspwm, if you wanted to know): { "id": 29360131, "splitType": "vertical", "splitRatio": 0.5, "birthRotation": 90, "vacant": true, "sticky": false,...
0
votes
1answer
26 views

How do I use sed to change },{“Foo” to }\n{“Foo”?

I have a 55MB JSON file with a huge number of objects that are separated by },{. I would like to have one object per line and get rid of the comma. For one thing, I'd like to be able to look at the ...
0
votes
2answers
267 views

Convert sqlite output to json

I want to format sqlite output in json format from the command line. Currently I have .csv output that looks like this: label1,value1 label2,value2 label3,value3 ... Now I'd like to have it ...
1
vote
1answer
178 views

XMLstarlet for JSON?

Is there a tool that is similar to XMLstarlet but works on JSON instead of XML? My usecase: extract certain values from hierarchical JSON documents, as they are returned by some REST APIs. Something ...
2
votes
2answers
196 views

sed to match zero or more number of spaces in a string

function getVal { sedPattern='s/^.*"keyVal":"\([^"]*\)".*$/\1/' finalSedPattern=${sedPattern/keyVal/$2} echo $(sed $finalSedPattern <<< $1) } This is my Json parser written using sed. ...
0
votes
1answer
2k views

Editing a child JSON element value with jq

I'm trying to use jq in order to change a child's value. For instance, I want to change the value of "test2" from ["yo", "bye"] to ["hi"]. { "title": "hello", "body": { "test1": 123, ...
-1
votes
1answer
757 views

How to prettyprint json using jq standalone?

Currently, when I want to pretty-print a json file using jq, I use: cat file.json | grep jq . Yet I would expect for jq to accept a file name as argument without having to fallback on cat. The man ...
3
votes
3answers
574 views

How do I convert the output of ps(1) to JSON?

I want to convert the output of the command ps to JSON in order to process it as structured data (with jq in this particular case). How do I do that? The output looks like the following: PID TTY ...
10
votes
4answers
2k views

How to extract data from a JSON file

I have bin searching a solution for my question but didn't find a or better said I did not get it with what I found. So lets talk about what my problem is about. I am using a Smart Home Control ...
1
vote
3answers
71 views

awk script to delete blocks in json

I have a newline delimited JSON file with entries like this: {"id":"eprints.ulster.ac.uk/view/year/2015.html","title":"Items where Year is 2015 - Ulster Institutional Repository","url":"eprints....
0
votes
1answer
611 views

How to customize a segment of powerline(for Bash shell $PS1 layout, specifically)?

According to the documentary, powerline use ~/.config/powerline/config.json for configurations. Since I don't quite like the layout of $PS1 by default, I made some change in keyword cwd as following. ...
1
vote
6answers
164 views

update the json file

I have a file, actually json file. How I can add a comma to the end of every but the last line ? For example: {"a":1, "b":1, "c":2} {"a":3, "b":3, "c":1} {"a":1, "b":2, "c":3} What I want: {"a":1, "...
2
votes
3answers
91 views

Delete Entries in File if the Same Entry Exists in a Master File

I have a JSON master config file whose value may be overwritten by a specific account's config file (also in JSON). The Master file has this structure: { "section1Configs": { "setting01": ...
0
votes
1answer
415 views

How to escape an input string in Bash [closed]

I'm using the jq tool to handle some JSON in bash. Just one problem, while using this line: PB_ACL="acl="`echo $IMGREQ | jq -r'.data.acl'` Result: echo $PB_ACL // acl= The expected value jq ...
0
votes
2answers
43 views

Saving a piped value went wrong

I installed jq to handle some JSON with bash. But somehow piping the JSON string to jq in combination with saving it's output to another variable went wrong. TEST='{"foo": "bar"}' PB_SIG=$TEST | jq '....
6
votes
3answers
623 views

Why does `cat` seem to iterate over JSON arrays?

I'm puzzled by this behaviour of cat when trying to output a heredoc containing JSON in bash 3.2: input: $ cat <(cat <<EOF > {"x":[{"a":1,"b":2}]} > EOF) output: {"x":["a":1]} {"x":[...
2
votes
4answers
564 views

Is there a CLI tool that would prettify a JSON string [closed]

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 ...
4
votes
3answers
773 views

Convert /proc/cpuinfo to a JSON in linux bash

I'd like to convert the entire entry of a cat /proc/cpuinfo to a JSON of "key" : "value". Is this possible? I tried to explode the string using \n in hopes that I could get each line and then I could ...
-2
votes
1answer
431 views

How to parse json output through shell / Python [closed]

I am running a curl command which gives me json response. Now I want to parse the response output to get the keys and corresponding values from the output or getting value for a particular key. I ...
1
vote
1answer
742 views

single jq command with multiple output possible?

I have a JSON log file test.log: {"type":"1","fname":"AAA","lname":"bbb" } {"type":"2","state":"gujarat" } {"type":"3","city":"ahmedabad" } {"type":"3","city":"rajkot" } {"type":"1","...
2
votes
1answer
220 views

jq parse json log file

I have json log file like {"type":"1","fname":"AAA","lname":"bbb" } {"type":"2","state":"gujarat" } {"type":"3","city":"ahmedabad" } {"type":"3","city":"rajkot" } {"type":"1","fname":"ccc","lname":"...