Rust
docs.rs โบ jsonschema
jsonschema - Rust
For simple use cases where you need to validate an instance against a schema once, use is_valid or validate functions: use serde_json::json; let schema = json!({"type": "string"}); let instance = json!("Hello, world!"); assert!(jsonschema::is_valid(&schema, &instance)); assert!(jsonschema:...
JSON Schema Validator
jsonschemavalidator.net
JSON Schema Validator - Newtonsoft
This schema validator is built using Json.NET Schema and C#. public class JsonSchemaController : ControllerBase { [HttpPost] [Route("api/jsonschema/validate")] public ValidateResponse Validate(ValidateRequest request) { // Load schema JSchema schema = JSchema.Parse(request.Schema); JToken json = JToken.Parse(request.Json); // Validate json IList<ValidationError> errors; bool valid = json.IsValid(schema, out errors); // Return error messages and line info to the browser return new ValidateResponse { Valid = valid, Errors = errors }; } } public class ValidateRequest { public string Json { get; set; } public string Schema { get; set; } } public class ValidateResponse { public bool Valid { get; set; } public IList<ValidationError> Errors { get; set; } }
Videos
13:45
JSON Schema Validation in Python: Bring Structure Into JSON - YouTube
17:13
Validate JSON with JSON Schema
Validate JSON Schema Using jsonschema Library
04:56
Validate JSON with JSON Schema - YouTube
03:26
Validate Response Data With JSON Schema - YouTube
12:38
JSON Schema Validation in Rest Assured - YouTube
JSONLint
jsonlint.com โบ json-schema
JSON Schema Validator - Validate JSON Against Schema | JSONLint | JSONLint
Validate your JSON data against a JSON Schema. Catch structural errors, type mismatches, and missing required fields before they cause bugs.
Readthedocs
python-jsonschema.readthedocs.io โบ en โบ v4.8.0 โบ validate
Schema Validation - jsonschema 4.8.0 documentation
It is assumed to be valid, and providing an invalid schema can lead to undefined behavior. See Validator.check_schema to validate a schema first. resolver โ an instance of jsonschema.RefResolver that will be used to resolve $ref properties (JSON references).
Jsonschema
jsonschema.dev
JSON Schema Validation
JSON Schema Validation, in browser, using ajv, with linting, and shareable schemas
json-everything
docs.json-everything.net โบ schema โบ basics
JsonSchema.Net Basics | json-everything
2 days ago - JsonSchema.Net implements keywords using singleton keyword handlers. These handlers are responsible for validating that the keyword data is valid in the schema, building any subschemas, and instance evaluation.
jsonschema
python-jsonschema.readthedocs.io โบ en โบ latest โบ validate
Schema Validation - jsonschema 4.26.1.dev25+gad0a1b301 documentation
The Basics: The simplest way to validate an instance under a given schema is to use the validate function. The Validator Protocol: jsonschema defines a protocol that all validator classes adhere to...
JSON Schema
json-schema.org โบ understanding-json-schema โบ reference โบ conditionals
JSON Schema - Conditional schema validation
In this example, "country" is not a required property. Because the if schema also doesn't require the "country" property, it will pass and the "then" schema will apply. Therefore, if the "country" property is not defined, the default behavior is to validate "postal_code" as a USA postal code.
JSON Schema
json-schema.org
JSON Schema
Establish a common language for data exchange, no matter the scale or complexity of your project. Define precise validation rules for your data structures to create shared understanding and increase interoperability across different systems and platforms.
jsonschema
python-jsonschema.readthedocs.io โบ en โบ stable โบ validate
Schema Validation - jsonschema 4.26.0 documentation
The Basics: The simplest way to validate an instance under a given schema is to use the validate function. The Validator Protocol: jsonschema defines a protocol that all validator classes adhere to...
jsonschema
python-jsonschema.readthedocs.io โบ en โบ latest โบ errors
Handling Validation Errors - jsonschema 4.26.1.dev25+gad0a1b301 documentation
Each tree and child has a ErrorTree.errors attribute, a dict, that maps the failed validation keyword to the corresponding validation error. The best_match function is a simple but useful function for attempting to guess the most relevant error in a given bunch. >>> from jsonschema import Draft202012Validator >>> from jsonschema.exceptions import best_match >>> schema = { ...
GitHub
github.com โบ kaptinlin โบ jsonschema
kaptinlin/jsonschema: A powerful Go JSON Schema ...
Formats: Built-in validators for email, UUID, datetime, URI, etc. Registration: Register schemas for reuse and cross-references ... type User struct { Name string `jsonschema:"required,minLength=2,maxLength=50"` Email string `jsonschema:"required,format=email"` Age int `jsonschema:"minimum=18,maximum=120"` } // Generate schema from struct tags schema, err := jsonschema.FromStruct[User]() if err != nil { panic(err) } result := schema.Validate(userData)
Starred by 216 users
Forked by 23 users
Languages ย Go
Top answer 1 of 4
67
If you haven't check jsonschema library, it can be useful to validate data. JSON Schema is a way to describe the content of JSON. The library just uses the format to make validations based on the given schema.
I made a simple example from basic usage.
import json
from jsonschema import validate
# Describe what kind of json you expect.
schema = {
"type" : "object",
"properties" : {
"description" : {"type" : "string"},
"status" : {"type" : "boolean"},
"value_a" : {"type" : "number"},
"value_b" : {"type" : "number"},
},
}
# Convert json to python object.
my_json = json.loads('{"description": "Hello world!", "status": true, "value_a": 1, "value_b": 3.14}')
# Validate will raise exception if given json is not
# what is described in schema.
validate(instance=my_json, schema=schema)
# print for debug
print(my_json)
2 of 4
12
As you're using a JSON file, you can use this example:
import json
def validate(filename):
with open(filename) as file:
try:
data = json.load(file) # put JSON-data to a variable
print("Valid JSON") # in case json is valid
return data
except json.decoder.JSONDecodeError:
print("Invalid JSON") # in case json is invalid
GitHub
github.com โบ sourcemeta โบ jsonschema
GitHub - sourcemeta/jsonschema: The CLI for working with JSON Schema. Covers formatting, linting, testing, bundling, and more for both local development and CI/CD pipelines ยท GitHub
curl -fsSL https://raw.githubusercontent.com/sourcemeta/jsonschema/main/install -H 'Cache-Control: no-cache, no-store, must-revalidate' | /bin/sh
Starred by 250 users
Forked by 30 users
Languages ย Shell 76.6% | C++ 17.9% | CMake 4.8% | JavaScript 0.5% | Makefile 0.1% | Dockerfile 0.1%
Built In
builtin.com โบ software-engineering-perspectives โบ python-json-schema
How to Use JSON Schema to Validate JSON Documents in Python | Built In
Incorrect data types or missing some required fields will trigger the ValidationError. However, it should be noted that by default additional fields are allowed, which may or may not be what you want. If you want a strict schema and only allow fields that are defined by the properties keyword, you can specify the additionalProperties to be False: from jsonschema import validate schema = { "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "number"}, }, "required": ["name"], "additionalProperties": False } validate(instance={"name": "John", "age": 30, "job": "Engineer"}, schema=schema) # ValidationError: Additional properties are not allowed ('job' was unexpected)
GitHub
github.com โบ Stranger6667 โบ jsonschema
GitHub - Stranger6667/jsonschema: A high-performance JSON Schema validator for Rust ยท GitHub
use serde_json::json; fn main() -> Result<(), Box<dyn std::error::Error>> { let schema = json!({"maxLength": 5}); let instance = json!("foo"); // One-off validation assert!(jsonschema::is_valid(&schema, &instance)); assert!(jsonschema::validate(&schema, &instance).is_ok()); // Build & reuse (faster) let validator = jsonschema::validator_for(&schema)?; // Fail on first error assert!(validator.validate(&instance).is_ok()); // Iterate over errors for error in validator.iter_errors(&instance) { eprintln!("Error: {error}"); eprintln!("Location: {}", error.instance_path()); } // Boolean result assert!(validator.is_valid(&instance)); // Structured output (JSON Schema Output v1) let evaluation = validator.evaluate(&instance); for annotation in evaluation.iter_annotations() { eprintln!( "Annotation at {}: {:?}", annotation.schema_location, annotation.annotations.value() ); } Ok(()) }
Starred by 750 users
Forked by 117 users
Languages ย Rust 88.8% | Python 6.6% | Ruby 4.3%
jsonschema
python-jsonschema.readthedocs.io
jsonschema 4.26.0 documentation
>>> validate(instance={"name" : "Eggs", "price" : 34.99}, schema=schema) >>> validate( ... instance={"name" : "Eggs", "price" : "Invalid"}, schema=schema, ... ) Traceback (most recent call last): ... ValidationError: 'Invalid' is not of type 'number' It can also be used from the command line by installing check-jsonschema.
npm
npmjs.com โบ package โบ jsonschema
jsonschema - npm
January 7, 2025 - validator.attributes.contains = function validateContains(instance, schema, options, ctx) { if(typeof instance !== 'string') return; if(typeof schema.contains !== 'string') throw new jsonschema.SchemaError('"contains" expects a string', schema); if(instance.indexOf(schema.contains)<0){ return 'does not contain the string ' + JSON.stringify(schema.contains); } } var result = validator.validate("I am an instance", { type:"string", contains: "I am" }); // result.valid === true;
ยป npm install jsonschema
Published ย Jan 07, 2025
Version ย 1.5.0
Author ย Tom de Grunt
Repository ย https://github.com/tdegrunt/jsonschema