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.
557 questions
160
votes
1
answer
164k
views
How to prettyprint json using jq standalone?
Currently, when I want to pretty-print a json file using jq, I use:
cat file.json | jq .
Yet I would expect for jq to accept a file name as argument without having to fallback on cat.
The man page ...
121
votes
1
answer
142k
views
jq - select an attribute beginning with a string
input json:
[
{
"id": "89",
"hostname": "abcd"
},
{
"id": "89",
"hostname": "babcd"
}
]
How to modify below filter to get on output only hostname beginning with "abcd"?
$ jq ...
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": [],...
79
votes
4
answers
150k
views
Merge jq output into a comma separated string
I am trying to curl some URL which returns a json file, then I want to parse hosts from it and create a comma separated string.
I have the first part working
curl -s -u "admin:admin" -H "X-...
75
votes
2
answers
79k
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 ...
56
votes
4
answers
131k
views
Setting jq output to a Bash Variable [closed]
I'm using curl to get JSON back from a rest api like this:
content=$(curl -s -X GET -H "Header:Value" http://127.0.0.1:8200/etc)
echo "${content}"| jq -r '.data.value'
which produces the value I ...
52
votes
1
answer
73k
views
How to sort a stream of json objects by field value using jq
I'm starting with json that looks like this:
{
"object": "list",
"data": [
{
"id": "in_1HW85aFGUwFHXzvl8wJbW7V7",
"object&...
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?
38
votes
7
answers
28k
views
How to decompress jsonlz4 files (Firefox bookmark backups) using the command line?
There seems to be various JavaScript+browser specific ways of decompressing this, but isn't there some way to transform jsonlz4 files to something unlz4 will read?
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": [
{
"...
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.
...
29
votes
2
answers
28k
views
jq - print "-" for null values
input json:
{
"id": "3885",
"login": "050111",
"lastLoginTime": 1529730115000,
"lastLoginFrom": "192.168.66.230"
}
{
"id": "3898",
"login": "050112",
"lastLoginTime": null,
"...
26
votes
6
answers
100k
views
Bash variable substitution in a JSON string
I'm trying to create a JSON in BASH where one of the fields is based on the result of an earlier command
BIN=$(cat next_entry)
OUTDIR="/tmp/cpupower/${BIN}"
echo $OUTDIR
JSON="'"'{"hostname": "...
24
votes
2
answers
76k
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 '....