I am new to shell scripting,
I want to read a json variable's attribute values,
I have a sample json like -
{
"userId": 1,
"name": "jhonny",
"cities": [{
"id": 1,
"name": "KL"
}],
"otherinfo": {
"hobby": "reading",
"nickname": "john"
}
}
I tried the following script -
#!/bin/bash
temp='{"userId":1,"name":"jhonny","cities":[{"id":1,"name":"KL"}],"otherinfo":{"hobby":"reading","nickname":"john"}}'
echo $temp | jq .name
I get a test.sh: line 4: jq: command not found
I am following this -
Read JSON variable in Shell Script
Can someone help how I could extract cities[0].name
and otherinfo.nickname
from the shell variable?