Updating json file in place

Sometimes I need to update json config in place. One line command below requires two tools to be available locally — jq and sponge from moreutils. First it sets all required arguments to be processed by jq, then jq reads json and updates on the fly passing it afterwards to sponge, which actually writes the result.

ARG1=test && jq --arg ARG1 $ARG1 '.my_key = $ARG1' <path to json file> | sponge <path to json file>