This is my data for this example:
[
{
"date": "25-09-20",
"nbrMembers": 1,
"nbrWallets": 4
},
{
"date": "26-09-20",
"nbrMembers": 3,
"nbrWallets": 1
},
{
"date": "27-09-20",
"nbrMembers": 0,
"nbrWallets": 2
},
{
"date": "28-09-20",
"nbrMembers": 7,
"nbrWallets": 3
}
]
I need to transform the json with cumulate fields. This is the expected result:
[
{
"date": "25-09-20",
"nbrMembers": 1,
"nbrWallets": 4
},
{
"date": "26-09-20",
"nbrMembers": 4,
"nbrWallets": 5
},
{
"date": "27-09-20",
"nbrMembers": 4,
"nbrWallets": 7
},
{
"date": "28-09-20",
"nbrMembers": 11,
"nbrWallets": 10
}
]
This is what i'm doing to cumulate just one field:
jq 'foreach .[] as $row (0; . + $row.nbrMembers ; . as $x | $row | (.nbrMembers = $x))' test.json
I just don't know how to do this with multiples fields ?
Succinctly: