A command-line tool for validating JSON Structure schemas and instances.
cargo install json-structure --features cligit clone https://github.com/json-structure/sdk.git
cd sdk/rust
cargo build --release --features cli
# Binary at: target/release/jstructDownload from GitHub Releases:
| Platform | Architecture | File |
|---|---|---|
| Linux | x86_64 | jstruct-x86_64-unknown-linux-gnu.tar.gz |
| Linux | ARM64 | jstruct-aarch64-unknown-linux-gnu.tar.gz |
| Windows | x86_64 | jstruct-x86_64-pc-windows-msvc.zip |
| Windows | ARM64 | jstruct-aarch64-pc-windows-msvc.zip |
| macOS | Intel | jstruct-x86_64-apple-darwin.tar.gz |
| macOS | Apple Silicon | jstruct-aarch64-apple-darwin.tar.gz |
Homebrew (macOS/Linux):
brew tap json-structure/tap
brew install jstructChocolatey (Windows):
choco install jstructDebian/Ubuntu:
sudo dpkg -i jstruct_*.debRHEL/Fedora:
sudo rpm -i jstruct-*.rpmLinux/macOS:
curl -fsSL https://json-structure.org/install.sh | shWindows PowerShell:
iwr -useb https://json-structure.org/install.ps1 | iexValidate one or more JSON Structure schema files for correctness.
jstruct check [OPTIONS] <FILES>...Arguments:
<FILES>...- Schema file(s) to check. Use-for stdin.
Options:
-b, --bundle <FILE>- Bundle file(s) containing schemas for$importresolution. Can be specified multiple times.-f, --format <FORMAT>- Output format:text(default),json,tap-q, --quiet- Suppress output, use exit code only-v, --verbose- Show detailed validation information
Examples:
# Check a single schema
jstruct check person.struct.json
# Check multiple schemas
jstruct check schemas/*.struct.json
# Check schema with external dependencies
jstruct check --bundle common-types.json --bundle address.json order.struct.json
# Read from stdin
cat schema.json | jstruct check -
# JSON output for CI integration
jstruct check --format json schema.json
# Quiet mode for scripts
jstruct check -q schema.json && echo "Valid"Validate JSON instance files against a schema.
jstruct validate [OPTIONS] --schema <SCHEMA> <FILES>...Arguments:
<FILES>...- Instance file(s) to validate. Use-for stdin.
Options:
-s, --schema <SCHEMA>- Schema file to validate against (required)-b, --bundle <FILE>- Bundle file(s) containing schemas for$importresolution in the schema. Can be specified multiple times.-f, --format <FORMAT>- Output format:text(default),json,tap-q, --quiet- Suppress output, use exit code only-v, --verbose- Show detailed validation information
Examples:
# Validate a single instance
jstruct validate --schema person.struct.json alice.json
# Validate multiple instances
jstruct validate -s schema.json data/*.json
# Validate with schema that uses $import
jstruct validate -s order.struct.json -b common-types.json -b address.json order.json
# Read instance from stdin
cat data.json | jstruct validate -s schema.json -
# JSON output
jstruct validate -s schema.json --format json data.json| Code | Meaning |
|---|---|
0 |
All files valid |
1 |
One or more files invalid |
2 |
Error (file not found, JSON parse error, etc.) |
Human-readable output with symbols:
✓ person.struct.json: valid
✗ bad-schema.struct.json: invalid
- /$id: Missing required property "$id"
- /type: Unknown type "invalid_type"
Machine-readable JSON array:
[
{
"file": "person.struct.json",
"valid": true,
"errors": []
},
{
"file": "bad-schema.struct.json",
"valid": false,
"errors": [
{
"path": "/$id",
"code": "SCHEMA_MISSING_ID",
"message": "Missing required property \"$id\""
}
]
}
]Compatible with TAP consumers for CI/CD:
1..2
ok 1 - person.struct.json
not ok 2 - bad-schema.struct.json
- /$id: Missing required property "$id"
- /type: Unknown type "invalid_type"
JSON Structure schemas can use $import and $importdefs to reference definitions from
external schemas. When validating schemas that use these keywords, you need to provide
the referenced schemas as a bundle.
- Each bundle schema must have a
$idproperty with a URI - When the main schema uses
$import: "https://example.com/types.json", the validator looks for a bundled schema with$id: "https://example.com/types.json" - If found, the definitions from the bundled schema are available for resolution
Given these files:
common-types.json:
{
"$schema": "https://json-structure.org/meta/core/v0/#",
"$id": "https://example.com/common-types",
"definitions": {
"Address": {
"type": "object",
"properties": {
"street": { "type": "string" },
"city": { "type": "string" }
}
}
}
}order.struct.json:
{
"$schema": "https://json-structure.org/meta/core/v0/#",
"$id": "https://example.com/order",
"$import": "https://example.com/common-types",
"type": "object",
"properties": {
"orderId": { "type": "string" },
"shippingAddress": { "type": { "$ref": "#/definitions/Address" } }
}
}Validate with bundle:
jstruct check --bundle common-types.json order.struct.json- name: Validate schemas
run: |
jstruct check --format tap schemas/*.struct.jsonvalidate:
script:
- jstruct check --format json schemas/ > schema-results.json
artifacts:
reports:
dotenv: schema-results.json#!/bin/sh
# .git/hooks/pre-commit
SCHEMAS=$(git diff --cached --name-only --diff-filter=ACM | grep '\.struct\.json$')
if [ -n "$SCHEMAS" ]; then
jstruct check $SCHEMAS || exit 1
fifind . -name "*.struct.json" -exec jstruct check {} +# Validate request body
echo '{"name": "Alice", "age": 30}' | jstruct validate -s person.struct.json -
# Validate API response
curl -s https://api.example.com/person/1 | jstruct validate -s person.struct.json -jstruct check --format json schemas/*.json | jq '.[] | select(.valid == false)'# Using entr
ls schemas/*.json | entr -c jstruct check schemas/*.jsonMIT License - see LICENSE for details.