---
title: Update JSON File with Bash Using NodeJS
description: In this short post I'll show you a quick way to make simple edits to a .json file from the command line or using bash and NodeJS.
date: 2022-02-22
tags: Bash, JSON, NodeJS
source: https://brianchildress.co/blog/update-json-file-in-bash-with-node
---

# Update JSON File with Bash Using NodeJS

In this (very) short post I'll show you a quick way to make simple edits to a .json file from the command line or using bash and NodeJS. 

Let's say we want to update a value in a `data.json` file. With [NodeJS](https://nodejs.org/) installed on our system we can leverage the `-p` or `--print` command to evaluate a script and print the result. For us, the script is the _JSON.stringify()_ function that will evaluate our `.json` file and add or update certain values in the statement.

_Example:_

```sh
node -p "JSON.stringify({...require('./data.json'), key4: 'value4'}, null, 2)" > data.json
```

Inspired by this post: [Source](https://stackoverflow.com/questions/24942875/change-json-file-by-bash-script)
