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.
59 questions
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, ...
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?
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": [
{
"...
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
`...
-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,
...
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": ...
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": [],...
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.
...
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 "...
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": "...
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,
...
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 ...
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 ...
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 ...
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 ...