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
42
votes
7answers
159k 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?
8
votes
6answers
9k views

Convert output of tree command to json format

Is there a convenient way to convert the output of the *nix command "tree" to JSON format? Edit: I think I didn't describe my problem well enough. My goal is to convert something like: . |-- dir1 | ...
52
votes
9answers
244k views

How to parse JSON with shell scripting in Linux?

I have a JSON output from which I need to extract a few parameters in Linux. This is the JSON output: { "OwnerId": "121456789127", "ReservationId": "r-48465168", "Groups": [],...
12
votes
5answers
34k 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 ...
29
votes
3answers
32k views

Limit grep context to N characters on line

I have to grep through some JSON files in which the line lengths exceed a few thousand characters. How can I limit grep to display context up to N characters to the left and right of the match? Any ...
17
votes
8answers
54k views

Parse JSON using Python?

I have a JSON file members.json as below. { "took": 670, "timed_out": false, "_shards": { "total": 8, "successful": 8, "failed": 0 }, "hits": { "total": 74, ...
8
votes
2answers
8k views

JSON parsing on the shell

How can I parse JSON output on the shell? For example, Amazon Web Services provides a CLI to retrieve the status of your instances: $ aws ec2 describe-instances <my_instance_id> But the ...
4
votes
2answers
12k 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 ...
5
votes
5answers
703 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
0answers
229 views

process JSON format with JQ tools [closed]

I want check format keys in bash script. In my json if any keys match this format key[0-9][0-9]_$ my script exit 1 else exit 2. I want use JQ tools. Bash: #!/bin/bash json=$(cat <<EOF {"key11"...
1
vote
2answers
246 views

JQ (GET ID based on NAME)

I get a long list of such arrays { "id": "byu6g6c4cjys5mdkg5znh8ju8c", "create_at": 1511875272294, "update_at": 1511875272294, "delete_at": 0, "display_name": "BMA", "name": "...
4
votes
1answer
3k views

Match keys with regex in jq [closed]

I'm writing a script that analyses JSON input (jsonfile): { "key11":1010,"key11_yes":13,"key11_no":14, "key12":12120,"key12_yes":9,"key12_no":25, "key13":12103,"key13_yes":13,"key13_no":20 ...
1
vote
2answers
4k 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 ...
3
votes
1answer
864 views

How to combine strings from JSON values, keeping only part of the string?

I have sample: "name": "The title of website", "sync_transaction_version": "1", "type": "url", "url": "https://url_of_website" I want to get the following ...
2
votes
1answer
688 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
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
vote
1answer
115 views

Two consecutive OPs after pipe or two jq OPs in one run?

I have to extract data from a slightly mis-formatted JSON string, hence I first pass it through sed & awk. What I have is a command like: `sed 's/},/},\n/g' test.json |awk '/"characater"/ { gsub("...
0
votes
2answers
807 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.) ...
0
votes
2answers
889 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
185 views

jq: parse json file with constraint from other field [duplicate]

Extend of this question: How to combine strings from JSON values, keeping only part of the string? Above link's output also include the "name" of folder type, need to exclude these "type": ...