Skip to main content

json-update

json-update updates the values of specified keys in any JSON file.

Configuration

NameTypeRequiredDescription
pathstringYPath to a JSON file. This path is relative to the temporary workspace that Kargo provisions for use by the promotion process.
updates[]objectYThe details of changes to be applied to the file. At least one must be specified.
updates[].keystringYThe key to update within the file. For nested values, use a JSON dot notation path. See sjson documentation for supported syntax.
updates[].valueanyYThe new value for the key. Typically specified using an expression. Supports strings, numbers, booleans, arrays, and objects.

Output

NameTypeDescription
commitMessagestringA description of the change(s) applied by this step. Typically, a subsequent git-commit step reference this output and aggregate this commit message fragment with other like it to build a comprehensive commit message that describes all changes.

Examples

Common Usage

In this example, a JSON file's values are updated according to changes in a container image tag. After cloning the repository and clearing the output directory, the json-update step updates the image.tag field in configs/settings.json to match the tag of the image being promoted. This demonstrates how to modify nested JSON values using dot notation (similar to how you would reference nested object properties).

This pattern is commonly used when managing configuration files that need to stay synchronized with deployed container versions.

info

For more information on imageFrom and expressions, see the Expressions documentation.

vars:
- name: gitRepo
value: https://github.com/example/repo.git
steps:
- uses: git-clone
config:
repoURL: ${{ vars.gitRepo }}
checkout:
- commit: ${{ commitFrom(vars.gitRepo).ID }}
path: ./src
- branch: stage/${{ ctx.stage }}
create: true
path: ./out
- uses: git-clear
config:
path: ./out
- uses: json-update
config:
path: configs/settings.json
updates:
- key: image.tag
value: ${{ imageFrom("my/image").Tag }}
# Render manifests to ./out, commit, push, etc...