Reputation: 991
I am having the file named loaded.json which contains the below json data.
{
"name" : "xat",
"code" : "QpiAc"
}
{
"name" : "gbd",
"code" : "gDSo3"
}
{
"name" : "mbB",
"code" : "mg33y"
}
{
"name" : "sbd",
"code" : "2Vl1w"
}
Form the shell script i need to read and parse the json and add the result to the variable and print it like this.
#!/bin/sh
databasename = cat loaded.json | json select '.name'
echo $databasename
When i run the above script i am getting error like
databasename command not found
json command not found
I am new to shell script please help me to solve this problem
Upvotes: 13
Views: 63367
Reputation: 6702
Replace this,
databasename=`cat loaded.json | json select '.name'`
or try jq
command,
databasename=`jq '.name' loaded.json`
For more information read this article.
Upvotes: 24
Reputation: 991
I can able to get the result using jq command like below
databasename=`cat loaded.json | jq '.name'`
Upvotes: 4