Use jq to edit an existing file in-place


WARNING! If you try this on an invalid JSON file, it will get erased. In a script, you can do set -o pipefail to prevent this.

The jq tool is amazing, but it won’t change an existing file in-place. Here’s a hack using ex to get around that:

jq ... input.json | ex -sc 'wq!input.json' /dev/stdin

More info on ex

Date: 2016-08-10

Tags:  json

Share: