Update JSON file Key Values from a key/value list, JSON/YAML data or source file path for Build, Release or Publishing.
Zero configuration action to update a manifest.json file version value to a release tag.
Allows setting multiple key/value pairs, setting nested keys, and merging from source JSON data.
- name: 'Update JSON'
uses: cssnr/update-json-value-action@v2You can also specify the keys/values or provide source JSON/YAML data or file.
See the Inputs and Examples for more options.
Note
Please submit a Feature Request for new features or Open an Issue if you find any bugs.
| Input | Default Value | Description of Input |
|---|---|---|
| file | manifest.json |
JSON File Path |
| data | - | Input JSON/YAML Data or File |
| keys | version |
Keys to Update |
| values | github.ref_name |
Values to Set |
| write | true |
Write Updates to file |
| output | file | Write to a different file. |
seperator |
. |
Nested keys Seperator |
| summary | true |
Add Summary to Job |
This is the JSON file you wish to update, such as package.json.
Default: manifest.json
This can be a JSON/YAML string, or a file path to a JSON/YAML file.
When providing data the keys/values are omitted.
👀 View Example Data
YAML data.
with:
data: |
version: ${{ github.ref_name }}
scripts:
test: echo successJSON Data
with:
data: |
{
"version": "${{ github.ref_name }}",
"scripts": {"test": "echo success"}
}See the Examples for more details.
If this is a file path, the file will be read, otherwise the value will be used. The resulting string is then parsed as JSON or YAML to an Object.
Finally, the data is merged using deepmerge.
List of keys and values to update, one per line.
👀 View Example Keys/Values
Single Key and Value.
with:
keys: version
values: ${{ github.ref_name }}Multiple Keys and Values.
with:
keys: |
version
scripts.test
values: |
${{ github.ref_name }}
echo successSee the Examples for more details.
This input is omitted when providing data.
If you omit these inputs, it will update the version key to the ref_name of the workflow.
Default keys: version
Default values: ${{ github.ref_name }}
Alternatively, you can provide data as a JSON/YAML string, see data.
This writes the resulting JSON back to the file.
To write to a different file, set the output
Default: true
To write the results to a different file set the path to the file here. Directories will be created as necessary.
Default: file
Write a Summary for the job. To disable this set to false.
To view a workflow run, click on a recent Test job (requires login).
👀 View Example Summary
💾 ✔️ package.json
Keys/Values
| Key | Value |
|---|---|
| name | test |
| scripts.lint | test |
Results
{
"name": "test",
"scripts": {
"build": "ncc build src/index.js",
"build:watch": "npm run build -- --watch",
"lint": "test"
},
"dependencies": {
"@actions/core": "^1.11.1"
},
"devDependencies": {
"@eslint/js": "^9.20.0",
"@vercel/ncc": "^0.38.3",
"eslint": "^9.20.1",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-prettier": "^5.2.3",
"prettier": "^3.5.1"
}
}Inputs
| Input | Value |
|---|---|
| file | package.json |
| keys | name,scripts.lint |
| values | test,test |
| write | true |
| seperator | . |
If no inputs are passed, the manifest.json file's version key is updated to the ${{ github.ref_name }}.
- name: 'Update JSON'
uses: cssnr/update-json-value-action@v2| Output | Output Description |
|---|---|
| result | Updated JSON String |
- name: 'Update JSON'
id: json
uses: cssnr/update-json-value-action@v2
- name: 'Echo Result'
run: echo '${{ steps.json.outputs.result }}'💡 Click on an example heading to expand or collapse the example.
Manually set file, key and value
- name: 'Update JSON'
uses: cssnr/update-json-value-action@v2
with:
file: manifest.json
keys: version
values: ${{ github.ref_name }}Setting an additional key value pair
- name: 'Update JSON'
uses: cssnr/update-json-value-action@v2
with:
keys: |
version
version_name
values: |
${{ github.ref_name }}
"Release ${{ github.ref_name }}"Set a nested key w/ default seperator
- name: 'Update JSON'
uses: cssnr/update-json-value-action@v2
with:
file: src/manifest.json
keys: |
meta.version
values: |
"Release ${{ github.ref_name }}"Merge Source YAML data
- name: 'Update JSON'
uses: cssnr/update-json-value-action@v2
with:
file: package.json
data: |
version: ${{ github.ref_name }}
scripts:
test: echo successMerge Source JSON data
- name: 'Update JSON'
uses: cssnr/update-json-value-action@v2
with:
file: package.json
data: |
{
"version": "${{ github.ref_name }}",
"scripts": {"test": "echo success"}
}Merge Source File
- name: 'Update JSON'
uses: cssnr/update-json-value-action@v2
with:
file: package.json
data: src/source.jsonFor more examples, you can check out other projects using this action:
https://github.com/cssnr/update-json-value-action/network/dependents
The following rolling tags are maintained.
| Version Tag | Rolling | Bugs | Feat. | Name | Target | Example |
|---|---|---|---|---|---|---|
| ✅ | ✅ | ✅ | Major | vN.x.x |
vN |
|
| ✅ | ✅ | ❌ | Minor | vN.N.x |
vN.N |
|
| ❌ | ❌ | ❌ | Micro | vN.N.N |
vN.N.N |
|
| latest | ✅ | ✅ | ✅ | Latest | vX.X.X |
latest |
You can view the release notes for each version on the releases page.
The Major tag is recommended. It is the most up-to-date and always backwards compatible. Breaking changes would result in a Major version bump. At a minimum you should use a Minor tag.
The latest tag always points to the latest release regardless of the version number.
For general help or to request a feature, see:
- Q&A Discussion: https://github.com/cssnr/update-json-value-action/discussions/categories/q-a
- Request a Feature: https://github.com/cssnr/update-json-value-action/discussions/categories/feature-requests
If you are experiencing an issue/bug or getting unexpected results, you can:
- Report an Issue: https://github.com/cssnr/update-json-value-action/issues
- Chat with us on Discord: https://discord.gg/wXy6m2X8wY
- Provide General Feedback: https://cssnr.github.io/feedback/
For more information, see the CSSNR SUPPORT.md.
If you would like to submit a PR, please review the CONTRIBUTING.md.
Please consider making a donation to support the development of this project and additional open source projects.
Additionally, you can support other GitHub Actions I have published:
- Stack Deploy Action
- Portainer Stack Deploy Action
- Docker Context Action
- Actions Up Action
- VirusTotal Action
- Mirror Repository Action
- Update Version Tags Action
- Docker Tags Action
- Update JSON Value Action
- JSON Key Value Check Action
- Parse Issue Form Action
- Cloudflare Purge Cache Action
- Mozilla Addon Update Action
- Package Changelog Action
- NPM Outdated Check Action
- Label Creator Action
- Algolia Crawler Action
- Upload Release Action
- Check Build Action
- Web Request Action
- Get Commit Action
❔ Unpublished Actions
These actions are not published on the Marketplace, but may be useful.
- cssnr/create-files-action - Create various files from templates.
- cssnr/draft-release-action - Keep a draft release ready to publish.
- cssnr/env-json-action - Convert env file to json or vice versa.
- cssnr/push-artifacts-action - Sync files to a remote host with rsync.
- smashedr/update-release-notes-action - Update release notes.
- smashedr/combine-release-notes-action - Combine release notes.
📝 Template Actions
These are basic action templates that I use for creating new actions.
- js-test-action - JavaScript
- ts-test-action - TypeScript
- py-test-action - Python (Dockerfile)
- docker-test-action - Docker (Image)
Note: The docker-test-action builds, runs and pushes images to GitHub Container Registry.
For a full list of current projects visit: https://cssnr.github.io/