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.

JSON (JavaScript Object Notation) is a lightweight text-based data representation format. It coincides with JavaScript syntax. It aims at being both human-readable and machine-readable, although its readability for humans is hindered by excessive use of quotes and not enforcing indentation so hierarchical data structures are often not recognised as such.

Although a textual format, the complexities of free formatting make JSON difficult if not impossible to parse with awk, sed etc, unless severe formatting restrictions are imposed that are not part of the JSON specification. It is generally recommended to use a proper JSON parser to handle extraction and manipulation of JSON files, even if (currently) your files are so restricted that line oriented tools might work.

Useful resources

commandline tools

  • json_pp
  • yaml (JSON is a subset of YAML 1.2)
537 questions
14
votes
4 answers

Is there a shell one-liner to convert JSON to BSON?

Is there a shell one-liner to convert JSON to BSON? Something suitable for one-off execution, or a shell script? bsondump from MongoDB goes the inverse way, but I'm clueless as to what I can use to go from JSON to BSON. There's no bsonundump, e.g.
nmr
  • 262
10
votes
1 answer

extracting the CmdName_Word - Word from a morbig-generated JSON file

I would like to extract the commands from arbitrary shell scripts. I've used morbig (hat tip to Michael Homer for the suggestion!) to generate a JSON file from a shell script. As an example, this shell script: #!/bin/sh echo hi false || echo…
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
7
votes
3 answers

How to process JSON with strings containing invalid UTF-8

A large (and growing) number of utilities on Unix-like systems seem to be choosing the JSON format for data interchange¹, even though JSON strings cannot directly represent arbitrary file paths, process names, command line arguments and more…
6
votes
6 answers

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-e70a2fe8fd0531ad1f87de49f03537a6", "type" : "STORE", …
3
votes
1 answer

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":"ddd" } I run following command jq -c…
vimal
  • 101
2
votes
1 answer

How to determine path to a deeply nested json field

How does one go about contructing the path to a deeply nested field from a large json document. The approach I've typically used is to flatten the JSON using a jq expression. map ( with_entries(select(.key != "fields")) + (.fields |…
1
vote
4 answers

convert data in columns to json

I've data in text file in format: alex street1 253465873 alex123@google.com john street2 442893646 3jj33@google.com kevin street3 125234763 ke1vn@yahoo.com I need to convert this data to json format with headers: "name" "street" "phone" "e-mail"
0
votes
2 answers

Is it possible to read the very first value of the JSON response

Here is a JSON response I am receiving from a server: { "GoUZm0F3r-rZ0tItdurVfPLCAfBGrnvF32": { "entityId": "GoUZm0F3r-rZ0tItdurVfPLCAfBGrnvF32", "mergePolicy": { "id": "02596943-2bb0-497f-815c-ffc69bf4b9c0" …
Ashish
  • 1
0
votes
1 answer

convert .txt file data into json format

I have user.txt log file which have this data below and I want to convert it in json format. {"user":"Demo…
wasim
  • 1
  • 1
  • 2
0
votes
1 answer

How to prettify json from ngrep capture?

Way I found to prettify JSON messages from ngrep command: sudo ngrep -t -W byline port 2012 -d lo | grep "^{" | jq . TL;DR We use to check the behavior of our app using ngrep, the messages inside the app uses JSON to share data. However trying to…
0
votes
5 answers

How to remove "" in output list?

I used a command to get a list of IP from EC2. The result so far i got is a list like this: [ "172.31.11.7", "172.31.48.141", "172.31.64.201", "172.31.64.149", "172.31.64.148", "172.31.64.111" ] I want to get result as:…
The One
  • 4,862