CLI Usage
Use Property Validator from the command line to validate JSON files against schemas.
Installation
bash
cd property-validator
npm link # Enable 'propval' command globallyBasic Usage
Validate JSON File
bash
propval --schema schema.json --data data.jsonExample schema.json:
json
{
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "number" }
}
}Example data.json:
json
{
"name": "Alice",
"age": 30
}Output:
✓ Validation passedValidation Failure
bash
propval --schema schema.json --data invalid.jsonOutput:
✗ Validation failed at age: expected number, got stringCLI Options
--schema <file>— Path to JSON schema file (required)--data <file>— Path to JSON data file to validate (required)--verbose— Show detailed error information--json— Output results as JSON--help— Show help message
Output Modes
Standard Output (Default)
bash
propval --schema schema.json --data data.jsonOutput:
✓ Validation passedJSON Output
bash
propval --schema schema.json --data data.json --jsonOutput:
json
{
"ok": true,
"value": {
"name": "Alice",
"age": 30
}
}Verbose Mode
bash
propval --schema schema.json --data invalid.json --verboseOutput:
✗ Validation failed
Error Details:
Path: age
Expected: number
Actual: string
Value: "thirty"
Full error: Validation failed at age: expected number, got stringExit Codes
0— Validation passed1— Validation failed2— Invalid arguments or file not found
Examples
Validate API Response
bash
# Fetch API response
curl https://api.example.com/user/1 > response.json
# Validate against schema
propval --schema user-schema.json --data response.jsonValidate Configuration File
bash
propval --schema config-schema.json --data config.jsonBatch Validation
bash
# Validate multiple files
for file in data/*.json; do
propval --schema schema.json --data "$file" || echo "Failed: $file"
doneNext Steps
- Library Usage - Use in your code
- Examples - Real-world scenarios
- API Reference - Complete API