https://github.com/developerstoolbox/validate-json
A bash script that will allow you to validate a JSON string.
https://github.com/developerstoolbox/validate-json
json json-validate wolfsoftware
Last synced: 3 months ago
JSON representation
A bash script that will allow you to validate a JSON string.
- Host: GitHub
- URL: https://github.com/developerstoolbox/validate-json
- Owner: DevelopersToolbox
- License: mit
- Created: 2021-02-26T16:26:49.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-09-29T05:03:33.000Z (4 months ago)
- Last Synced: 2025-09-29T06:24:22.143Z (4 months ago)
- Topics: json, json-validate, wolfsoftware
- Language: Shell
- Homepage:
- Size: 200 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Citation: CITATION.cff
- Codeowners: .github/CODEOWNERS
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
## Overview
This is a very simple tool for validating a JSON string. It utilises [jq](https://stedolan.github.io/jq/) for this purpose and wraps the output into something more consumable within other scripts.
> Also see: [json-lint](https://github.com/CICDToolbox/json-lint) for out travis plugin that performs a similar function.
## Usage
There are 4 different options when it comes to using the validation tool.
1. You can validate a raw json string
2. You can validate the contents of a file
3. You can just make use of error / return codes
4. You can be given error messages as well as return codes
The first 2 options are handled by 2 different exposed functions.
### Raw string
```shell
source validate-json.sh
validate_json ""
```
### From file
```shell
source validate-json.sh
validate_json_from_file ""
```
> This function will load the file contents into a string and then execute validate_json, so the final validation method is exactly the same to ensure identical results.
In additional to the two different wants to pass the data to the validator there are also 2 different ways to get data out of the validator.
### Verbose Mode (default)
Verbose mode will display messages relating to the validity of the string, either everything was ok, or the specific error message returned by jq. It will also use return codes for success (0) and failure (1).
```shell
source validate-json.sh
validate_json_from_file ""
```
### Silent Mode
This mode will suppress all output to the screen and will only use return codes.
```shell
silence_messages=true
source validate-json.sh
validate_json_from_file ""
```
> This is particularly useful if you want to embed the validation into another script and take different actions depending on the result.
#### Embedding Silent Mode
```shell
silence_messages=true
source validate-json.sh
if validate_json_from_file ""; then
go_perform_some_action_on_data
else
do_something_else_like_raise_an_error
fi
```