I have json like this:
[
{
"id": "1"
},
{
"id": "2"
},
{
"id": "3"
}
]
I call some "sizes.sh" that give me result:
10
20
30
How can I update my original json with these results, so it will look:
[
{
"id": "1",
"size": 10
},
{
"id": "2",
"size": 20
},
{
"id": "3",
"size": 30
}
]
2
Answers
Here is a way:
jq
cannot "update" a file, you’ll have to let the shell do it. Assuming a POSIX shell, you could redirect the output to a temporary file using>
, and overwrite the original on success usingmv -f
: