JSON Validate Utility
Part of the Using JSON Schema project.
jsonvalidate
is a command line and library utility allowing JSON content
to be validated using JSON Schema content from local or remote sources, and
use of custom schema storage and URI access.
The utility uses the jsonschema library for the schema validation processing (GitHub repo).
For command line/script use, a console message is displayed and the process exits with 0 for success, 1 for failure.
Command Line / Script Use
To run the validation (command line or script), use the validate
command with a file name (path optional). For example, to check the file
example.json
against the schema example_schema.json
, use,
validate example.json example_schema.json
Library Function Use
validate (dataFile, schemaFile, refFiles, jsdbFile, callback)
For example,
from jsonvalidate import validate, VALID
dataFile = "example.json"
schemaFile = "example_schema.json"
refFiles = ["ref1_schema.json", "ref2_schema.json"]
jsdbFile = None
code, data, message = validate (dataFile, schemaFile, refFiles, jsdbFile)
if code == VALID:
print ("Valid JSON content");
else:
print ("Error: " + str (message))
Installation
The program can be installed using pip
, with the command,
pip install ujs-jsonvalidate
License
MIT