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
2
votes
2answers
565 views

How to build third-party Geany plugins?

After downloading and extracting Geany's JSON Prettifier, and installing yajl, the make command does raise this error: /bin/sh: 1: pkg-config: not found ./geany_json_prettifier.c:32:25: fatal error: ...
-1
votes
2answers
1k views

Find and replace using regex with sed [closed]

I'm trying to find and replace in a file: echo "$BRANCH_NAME" >> "$WORKING_DIR"/test.text sed -i '' "remote_paths/.*[\/]([^\"]*)/$BRANCH_NAME/g" "$WORKING_DIR"/sftp-config.json ... the ...
8
votes
3answers
21k 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 ...
1
vote
2answers
211 views

Generate .txt file with specific content from an invalid 3GB .json file

I have a file named users.json which is 3GB, and is invalid json. So what I'm trying to do is read the file's text content, and take the information that I need, which is the usernames contained in ...
-2
votes
1answer
256 views

Extracting text with jq [closed]

How can I use jq to extract the object with id 11 from the following JSON, in order to process the CPU Package Temperature? { "id":0, "Text":"Sensor", "Children":[ { "id":1, "Text":"PC15029", "...
1
vote
2answers
222 views

Parse JSON for specific values

I have this JSON file in a single line containing thousands of records and I want to copy out sections of it, corresponding to specific household names or card numbers. Attached is a sample ...
0
votes
2answers
3k views

Bash - loop through files and pull JSON value from corresponding keys in a master key file

I'm trying to make a bash script that loops through a file that contains a list of files (so it goes through each one of these files). While the files are open, I want to use another program (jq) to ...
1
vote
1answer
484 views

How to get javascript key path in long json files in Linux

I'm using several keys from a long javascript object, represented as json. Example: ... "stock": { "type": 'str', "properties": { "warehouse": { "type": 123 }, "retail": { ...
2
votes
2answers
857 views

Using JQ to get simple delimited output

How might one turn this: { "write": { "out": 0, "available": 128, "totalTickets": 128 }, "read": { "out": 7, "available": 249, "totalTickets": 256 } } Into 0 128 128 ...
1
vote
3answers
183 views

Parse value of a specific element in a random position of a JSON file

I would like to match the value after "sid" for VALUE1 (=789069) The problem is that the order of the lines is random. [{"cid":"PWER","data":[{"VALUE1":0}],"sid":"789069","units":"kWm","age":586667}, ...
-1
votes
2answers
183 views

insert new lines into a csv file obtained via curl on an api

I am trying to replace a string in a text file that is a CSV file. The row delimiter string is {"id": and want to insert a new line before each occurrence of it as the CSV file appears only as one row ...
1
vote
2answers
179 views

Replacing file contents with SED in 2 files

I have 2 files. File 1 looks like this: Company: "Acme CO" Address: "123 Main Street" Zip: "12345" File 2 is a JSON file with variables as placeholders for this data. For example, %%company%% ...
0
votes
2answers
1k views

Is it possible to not escape double quotes and get the right json format?

I want to submit json data using httpie. If I use double quotes and escape the double quotes surrounding the key, it works. json="[ \ { \ \"count\": 3 \ } \ ]" echo $json [ { "...
1
vote
3answers
68 views

How to extract a string based on a regex match from a unformatted file

I have a unformatted file returned form a SQL query, from which I need to find a regex match and extract a numeric string that follows. The number is enclosed between two double quotes. Note there ...
1
vote
1answer
5k 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
2answers
811 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.) ...
2
votes
1answer
1k 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
133 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 ...
1
vote
2answers
5k 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
978 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
453 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": ...
-1
votes
1answer
116 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 ...
4
votes
1answer
5k 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 ...
2
votes
2answers
701 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 ...
1
vote
1answer
502 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
60 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
3k 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 - --...
5
votes
2answers
21k 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": "...
10
votes
3answers
18k views

Merge jq output into a comma separated string [duplicate]

I am trying to curl some URL which returns a 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-...
1
vote
2answers
314 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" ], ...
3
votes
0answers
154 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 ...
2
votes
2answers
558 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 ...
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 ...
1
vote
2answers
1k 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
818 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:...
2
votes
1answer
1k 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
119 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 ...
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-...
2
votes
1answer
690 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", "...
9
votes
1answer
6k 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
991 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
4k 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: { ...
2
votes
4answers
2k 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
33 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 ...
1
vote
2answers
1k 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 ...
4
votes
1answer
831 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
5k 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. ...
6
votes
1answer
16k 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, ...
25
votes
1answer
16k 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
4answers
4k 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 ...