If we have a hello.json
$ echo '{"hello": "world"}' > hello.json
$ cat hello.json
{"hello": "world"}
and try to add "foo": "bar" to it using jq, the file hello.json becomes an empty file.
$ cat hello.json | jq --arg bar bar '. + {foo: $bar}'  > hello.json
$ cat hello.json 
On the other hand, if we had instead written the new JSON payload to world.json, we get the expected contents in world.json.
$ echo '{"hello": "world"}' > hello.json
$ cat hello.json
{"hello": "world"}
$ cat hello.json | jq --arg bar bar '. + {foo: $bar}'  > world.json
$ cat world.json 
{
  "hello": "world",
  "foo": "bar"
}
Is there a way to do this without installing new utilities like sponge?
 
    