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
50 views

Add 100 to decimals in Multiple TXT files

I am confused over this, so need some help. I have multiple txt files in one folder. And there's some content in those text files. Now there is one text "moveLimit":30, (comma is after the decimal). ...
1
vote
2answers
2k views

Identify .json files with empty arrays?

I have a folder with multiple .json files. There are certain files with empty arrays, Sample file : { "WarehouseActivity": [] } The file has no other data apart from the one shown above. I need to ...
2
votes
2answers
1k views

unix command formatting flattening nested json objects data

example input data format json data: { div1: { name: "some name", age: number, address_1: "some address", items: { item_x1: "some data", .. .. ...
2
votes
5answers
139 views

Parse du result using sed

Hello i am trying to parse the result of du command but i don't know how to do it without looping i execute the below command du -shm /var/vmail/mailboxes/domain/*/mail my result is a list e.g.: ...
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 "{\"...
11
votes
4answers
3k views

Why is the JSON content from heredoc not parsable?

I have a JSON fragment. The following does not work: VALUE=<<PERSON { "type": "account", "customer_id": "1234", "customer_email": "jim@gmail.com" } PERSON echo -n "$VALUE" | python -m ...
0
votes
1answer
94 views

Need to do SED filtering on a file

Just wanted to remove last occurrence of , from the below file using SED. ubuntu@kops:/mujahid$ cat change-resource-record-sets.json { "Comment": "Update record to reflect new IP address of home ...
0
votes
2answers
893 views

Adding array entries to existing JSON document from plain text input

I have a situation where i have output of one command, like this, 192.168.1.84 192.168.1.85 i want to use this, and make changes in another file, i.e add this ip addresses one after another like in ...
0
votes
1answer
466 views

Add escape character in front of all quotation marks in a file

I have a pretty big json file and I would like to add the escape character in front of all quotation marks in it. For example I want to change: "CaptureDuration":0 to \"CaptureDuration\":0. I tried ...
0
votes
0answers
73 views

Replace all contiguous newline chars to a single comma

I have this git log command: const command = [ `git log ${branch} -${count} --grep="${grep}"`, ` --pretty=format:'{"subject":"%s","body":"%b","commit":"%h","sanitized_subject_line":"%f",`, ...
0
votes
2answers
9k views

merging many json files into one

I have many json files of such format: sample file1: { "attributes": [ { "name": "Node", "value": "test" } ] } sample file2: { "attributes": [ { "name": "...
0
votes
2answers
1k views

jq filter: show whole structure with selection

I have following file1 json: { "name": "eye", "attributes": [ { "name": "Width", "value": "1920" }, { "name": "Height", "value": "1080" }, { "...
4
votes
1answer
7k views

Convert JSON to CSV [closed]

JSON file: "UserDetailList": [ { "UserName": "citrix-xendesktop-ec2-provisioning", "GroupList": [], "CreateDate": "2017-11-07T14:20:14Z", "UserId": "1234556", "Path": "/", "...
1
vote
1answer
197 views

Support with parsing JSON using sed needed

In Home Assistant it is possible to set the state of a switch by executing a command. I am migrating away from my old home automation and it offers a way to get the state, unfortunately not for one ...
1
vote
2answers
699 views

Using jq to get a structured output

I have the following json as my input for jq processing [ { "Category": "Disk Partition Details", "Filesystem": "udev", "Size": "3.9G", "Used": 0, "Avail":...
2
votes
3answers
814 views

Extract json array element based on a subelement value

We have the following example file ( very long file , this is short example ) "request_status" : "FAILED" { "href" : "http://localhost:8080/api/v1/clusters/sys41/requests/333", "Requests" : { ...
0
votes
1answer
565 views

How to remove a special character in my curl output using grep,sed or awk

I'm trying to remove \r\n in the output of my curl my code is: curl -s -u ian.guinto:W0lfg@ng131994 --request GET --url 'https://jira.toro.io/rest/api/2/issue/OJTSYSAD-829/comment' -H "Content-Type: ...
0
votes
2answers
179 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
311 views

openweathermap json to csv

I need to convert some json containing forecast data to csv (for use in gnuplot). Have tried a couple of json2csv utilities json sample: {"cod":"200","message":0.006,"cnt":40,"list":[{"dt":...
0
votes
0answers
931 views

Create JSON to be passed as an argument to a method that updates cloud foundry service

Trying to pass a JSON object from one shell script to another. If I send a JSON object with one value it works with the following: objectStorageCupsConfigData='{\"containerName\":""\"$...
1
vote
1answer
120 views

Getting URL address from file and check HTTP code

I'm creating bash script to check what HTTP code a given URL returning. I have file with about 50k of URLs in JSON format; it's the first one (head of file): "responseHeader":{ "status":0, "...
1
vote
1answer
205 views

get name values basing on a value of another attribute in the block

with jq, I'd like to get "name" value of blocks where "Media" attribute (under .session.attributeList) contains "node7000" string (in example json first array block matches it - there are two matching:...
20
votes
2answers
11k views

How to convert embedded (quoted) json string to json

I'm familiar with "jq" for parsing json. I work with one service that produces a json response where one of the properties is itself a json string. How do I convert that quoted value to a valid json ...
1
vote
3answers
17k views

How to replace an element in a JSON file?

I need to replace the following text: "name":["abc1234"], age:"24" with "name": "abc1234", age: "24"
0
votes
1answer
464 views

sed Argument List Too Long While Updating JSON [duplicate]

I've a JSON property which needs to be updated with base64. The flow is: prop_val=`base64 --wrap=0 < $prop_txt` sed -i 's@"property_specific": ""@"property_specific": "'"${prop_val}"'"@g' $...
3
votes
1answer
13k 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
1answer
6k views

jq add or update a value with multiple --arg

I have file.json in the structure of: { "connections": {} } I want to update the connections object with variables $1 and $2. I'm trying: jq --arg ssid "$1" --arg pass "$2" '.connections.$ssid = "...
1
vote
1answer
3k views

Using multiple wildcards in jq to select objects in a JSON file

I have a JSON file with thousands of records line by line in the following structure, with different values. Example: {"in": 5,"li": [{"st": 1508584161,"abc": 128416626,"ta": 33888}],"usr": {"is": "...
0
votes
1answer
707 views

Compare strings in a JSON object in a file

I have a json file with thousands of JSON objects such as below. I want to compare st1 against st2. For every object in the JSON file, if st1 is higher than st2, copy every object that matches into ...
1
vote
2answers
175 views

Can I use sed to insert a pattern into a file?

I want to generate a file that starts in the format: # topics-to-move.json { "topics": [], "version": 1 } with no { "topic": "<topic_name>" } entries in "topics":[]. I can grab the ...
3
votes
2answers
1k views

How to replace multiple lines with “sed” and convert to JSON?

{ "auth": 'log', "appid": 21, "custid": "599c1f910f53ada8468b4567", "hwid": "59e719ba0f53adfd6a8b4597" } 24/10/2017 12:44:24 -------------------------------------------------------------------...
1
vote
1answer
2k views

Parsing JSON with JQ

I'm using Bash to run the following script snippet on a Linux box. JSON file contents: [ { "id": 123456, "firstName": "John", "lastName": "Smith", "email": "user@domain.com" } ] The JSON file is ...
5
votes
5answers
706 views

parse colon separated value pairs

I've written a script that converts nmcli --mode multiline dev wifi into json but I'm finding it's inconsistent (breaks when results have a space), long, and hard to read. I'm wondering if it is ...
-2
votes
2answers
164 views

Read file until match pattern [closed]

I´m reading a file and I would like to get the info until I found a match. So having the file here https://ufile.io/182kx I would like to have the json info from lastActiveTimes: until I found ,...
0
votes
3answers
2k views

Retrieving values from json file using jq

How can I print the value after "games", "toys", "books"? Here's the output of jq '.' on the file: { "reports": [ { "games": 3, "toys": 0, "books": 3, ...
-1
votes
1answer
2k views

Unable to parse bash variables in curl command

Hey I am using conduit curl method to create tasks from post. It work fine when I run from terminal with hardcoded values. But when I try to execute it with variables it throws an error: Script: #!/...
-3
votes
2answers
135 views

how to capture the properties tag from json file [duplicate]

this is very short list of my json file: "slider-client" : { "properties_attributes" : { }, "properties" : { } } }, { "spark2-hive-site-override" : { "properties_attributes" : { }, ...
0
votes
1answer
65 views

Hadoop cluster with Ambari - best way to modify configurations

We have an Hadoop cluster, clients are installed on Linux Red Hat machines and central management via Apache Ambari. yum list | grep ambari-server ambari-server.x86_64 2.5.0.3-7 ...
1
vote
4answers
8k views

How to grep/print value of a key in json that is stored in a variable?

I have a variable with nested json, a={"content":[{"JOB_STATUS_ID":283739,"PROGRAM_ID":57,"STATUS":"Completed","**DATA_DATE**":"2017-03-09 00:00:00","**START_TIME**":"2017-03-10 00:46:13","END_TIME":"...
0
votes
2answers
28 views

Extract values based on pattern out of a line/list

I have list extracted from a json output as below. "Rel_70" "Rel_71" "Dev_795" "Dev_796" "Dev_797" "Devtest_10" "Devtest_12" Out of this, I want to extract values with Dev_* i.e I am interested to ...
0
votes
0answers
328 views

Convert JSON array of strings to file paths in Bash [duplicate]

Say I have a bash script with an JSON env variable that represents an array of filepaths: #!/usr/bin/env bash x_file_paths="[\"/Users/foo/bar\",\"/Users/foo/bar/baz\"]"; How can I turn that JSON ...
4
votes
2answers
13k views

Curl JSON encoded in UTF-8

Important note: I'm using Cygwin I retrieve JSON from a file that I alter before sending it to a server using curl. By now everything is ok except one thing, when the server receive the JSON, every ...
3
votes
1answer
553 views

bash string concatenation failed

Important note: I'm using Cygwin to run this script. I got a json string by executing result=$(jq -c ".docs[$docIndex] + { \"_rev\": \"rev\" }"<<<"$fileContent") Here is the JSON I get: {"...
4
votes
2answers
5k views

Split a sting field into an array in jq?

I have a json array returned from curl that looks like this: [ { "title": "Some Title", "tags":"tagA tag-B tagC" }, { "title": "Some Title 2", "tags":"tagA tagC" }, ... ] I'd like ...
1
vote
4answers
235 views

Transform plain data into json file

everyone. I am quite new with linux and I am learning a lot with all of you reading this site. I am into a bit of trouble with my accounting program and that's why I am recurring to you. I want to ...
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 ...
0
votes
2answers
87 views

JSON correct construction

I'm generating a JSON file with a shell script but I can't find a solution to automatically get rid of the last comma just before the ending "}". Here is my code: echo "{" >> out_file for i ...
0
votes
2answers
1k views

How to convert a JSON file into a different format

I am having a file having 100 lines in below format. { "type": "Feature", "properties": { "id":"01","score":"10000","Name": "ABC", "description": "<html xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/...
4
votes
1answer
2k views

How to convert a JSON's file tree structure into a single line?

I have a JSON file as below { "Foo": "ABC", "Bar": "20090101100000", "Quux": { "QuuxId": 1234, "QuuxName": "Sam" } } I want to convert it to the below {"Foo":"ABC",...
-1
votes
2answers
7k views

Earliest viewer for viewing .json files?

While almost all text-editors can view .json files, I am sure there are some or one which show .json files in all its glory. Could somebody share name or names of native .json viewers rather than text-...