I have JSON file named input.json wich contains following data
{
"Data": {
"Info": [
{
"tranID": "1",
"architecture": "thread_1",
"build": "110",
"win": "450"
},
{
"tranID": "2",
"architecture": "thread_2",
"build": "120",
"win": "455"
}
]
}
}
Here I want to write function which will get file name as input parameter and now inside function I want to read last Object array and two fields from which build and win ans stor there values is variable ex total which will contain addition of build and win and insert this value again inside JSON .
so that final JSON will look like
{
"Data": {
"Info": [
{
"tranID": "1",
"architecture": "thread_1",
"build": "110",
"win": "450"
},
{
"tranID": "2",
"architecture": "thread_2",
"build": "120",
"win": "455",
"total": "575"
}
]
}
}
I have tried reading initial JSON build fiels and tried to store it in variable just printed that variable but variable is not stroing that value it's coming empty .
varr = $jq '.Data.Info[-1].build' ${1}
echo $varr
also tried
varr=$(echo $jq '.Data.Info[-1].build' ${1})
echo $varr
echo not printing value
where ${1} is my input JSON file