Skip to main content

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.

8 votes
3 answers
5k views

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, ...
Stéphane Chazelas's user avatar
50 votes
8 answers
245k 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?
mythz's user avatar
  • 611
33 votes
6 answers
109k views

parse one field from an JSON array into bash array

I have a JSON output that contains a list of objects stored in a variable. (I may not be phrasing that right) [ { "item1": "value1", "item2": "value2", "sub items": [ { "...
JpaytonWPD's user avatar
17 votes
5 answers
20k 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? My goal is to convert something like: . |-- dir1 | |-- dirA | | |-- dirAA | | `-- dirBB | `-- dirB `...
roundrobin's user avatar
-1 votes
2 answers
5k views

\1 - what does this sed action mean?

I am using this sed command to extract a json value for a key, say MyKey.. sedPattern='s/^.*"myKey":"\([^"]*\)".*$/\1/' For a json string like, {"myKey" : 1, "yourKey": 2} It returns what i need, ...
user avatar
95 votes
8 answers
177k views

Using jq to extract values from column-oriented JSON and format in CSV

I have the below JSON file, with the data stored as columns enumerated by rank in an array: { "data": [ { "displayName": "First Name", "rank": ...
Kerim's user avatar
  • 951
89 votes
13 answers
542k 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": [],...
user3086014's user avatar
33 votes
6 answers
142k views

How to extract data from a JSON file

I have been searching for a solution for my question but didn't find a or better said I did not get it with what I found.  My problem is: I am using a Smart Home Control Software on a Raspberry Pi.  ...
Raul Garcia Sanchez's user avatar
23 votes
2 answers
40k views

cUrl : Argument list too long

I'm getting the error: Argument list too long when trying to use cUrl to send a file in base64 inside the body of my JSON. I'm using something like this: DATA=$( base64 "$FILE" ) curl -X POST -H "...
Mateo's user avatar
  • 333
21 votes
4 answers
64k views

jq - add objects from file into json array

I want to add an array with elements and value into an existing json file using jq. I already have a file (input.json) with { "id": 9, "version": 0, "lastUpdTs": 1532371267968, "name": "...
CLO's user avatar
  • 215
21 votes
8 answers
87k 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, ...
prayagupadhyay's user avatar
19 votes
2 answers
18k 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 ...
Amelio Vazquez-Reina's user avatar
17 votes
7 answers
121k views

How to find value of key-value in json in bash script

I'm trying to write a bash script with make s curl call and get a json document back. The json document has a key called access_token and I need to extract the value of this field. This is my json ...
HHH's user avatar
  • 297
9 votes
7 answers
3k views

Parse colon-separated value pairs (nmcli output) and convert to JSON fromat

I've written a script that converts the output of 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 wonder if ...
Philip Kirkbride's user avatar
5 votes
2 answers
15k views

Passing variable to jq to edit a json file

I am trying to pass a variable into jq like this '.Linux.date.$var' so far I have tried quoting them by name which is working fine. But I want to use variable to call them. I have this, which is ...
Rakib Fiha's user avatar

15 30 50 per page