If you wish to modify a JSON file directly from the command line, you can utilize the powerful tool called jq. Here's an example of how you can achieve this:
on: [push, pull_request]
name: Build
jobs:
build:
name: Example
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Update config.json
run: echo "`jq '.sampleArray[0].id="5"' config.json`" > config.json
- name: read config.json
run: cat config.json
Another method is to combine jq with sponge from the moreutils package and set an environment variable as shown below:
on: [push, pull_request]
name: Build
jobs:
build:
name: Example
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: install more-utils
run: sudo apt-get install moreutils
- name: Update config.json
env:
ID: 5
run: jq --arg id "$ID" '.sampleArray[0].id=$id' config.json | sponge config.json
- name: read config.json
run: cat config.json
The resulting output would be:
{
"version": "1",
"sampleArray": [{
"id": "5"
}],
"secondArray": [{
"secondId": "2"
}]
}