GitHub Action
JSON string/file validator
v1.0.0
Latest version
Basic action to validate if input file contents, or input string are valid JSON.
Possible use case might be to validate configuration updates/edits to a JSON file when a PR is raised.
Filename (all valid JSON): ${{ github.workspace }}/config-file.json
{
"example_meta": [
{
"meta_no": "57",
"meta_status": "active",
"meta_suburb": {
"name": "random_suburb",
"zip": "012012"
}
}
]
}
Include step to validate contents of file ${{ github.workspace }}/config-file.json
.
...
...
on:
pull_request:
...
jobs:
...
...
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: JSON string/file validator
uses: tonys-code-base/[email protected]
id: json-file-chk
with:
json-file-path: ${{ github.workspace }}/config-file.json
output:
Run tonys-code-base/[email protected]
with:
json-file-path: /runner/_work/***/***/config-file.json
Successfully parsed JSON file:
/runner/_work/***/***/config-file.json
Same file but with invalid JSON: ${{ github.workspace }}/config-file.json
{
"example_meta": [
{
"meta_no": "57",
"meta_status": "active",
"meta_suburb": {
"name": "random_suburb",
}
}
]
}
sample workflow output:
Run tonys-code-base/[email protected]
with:
json-file-path: /runner/_work/***/***/config-file.json
parse error: Expected another key-value pair at line 8, column 13
Error: Process completed with exit code 4.
...
...
jobs:
...
...
steps:
- name: JSON string/file validator
uses: tonys-code-base/[email protected]
id: json-str-chk
with:
json-string: >-
{
"example_meta": [
{
"meta_no": "57",
"meta_status": "active",
"meta_suburb": {
"name": "random_suburb",
"zip": "012012"
}
}
]
}
Output:
0s
Run tonys-code-base/[email protected]
Successfully parsed JSON string:
{
"example_meta": [
{
"meta_no": "57",
"meta_status": "active",
"meta_suburb": {
"name": "random_suburb",
"zip": "012012"
}
}
]
}