๐ŸŒ
JSON Schema Validator
jsonschemavalidator.net
JSON Schema Validator - Newtonsoft
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; } }
๐ŸŒ
JSON Schema
json-schema.org
JSON Schema
Define precise validation rules for your data structures to create shared understanding and increase interoperability across different systems and platforms. Create a clear, standardized representation of your data to improve understanding and collaboration among developers, stakeholders, and collaborators. Adopt JSON Schema with an expansive range of community-driven tools, libraries, and frameworks across many programming languages.
๐ŸŒ
GitHub
github.com โ€บ networknt โ€บ json-schema-validator
GitHub - networknt/json-schema-validator: A fast Java JSON schema validator that supports draft V4, V6, V7, V2019-09 and V2020-12 ยท GitHub
A fast Java JSON schema validator that supports draft V4, V6, V7, V2019-09 and V2020-12 - networknt/json-schema-validator
Starred by 1K users
Forked by 338 users
Languages ย  Java 98.6% | Python 1.4%
๐ŸŒ
Liquid Technologies
liquid-technologies.com โ€บ online-json-schema-validator
Free Online JSON Validator (JSON Schema)
Validates that a JSON document is syntactically valid, and that it conforms to the definition described by a JSON Schema.
๐ŸŒ
Jsonschema
jsonschema.dev
JSON Schema Validation
JSON Schema Validation, in browser, using ajv, with linting, and shareable schemas
๐ŸŒ
jsonschema
python-jsonschema.readthedocs.io โ€บ en โ€บ stable โ€บ validate
Schema Validation - jsonschema 4.26.0 documentation
If no $schema property is found, the default validator class is the latest released draft. Any other provided positional and keyword arguments will be passed on when instantiating the cls. ... If you are unfamiliar with protocols, either as a general notion or as specifically implemented by typing.Protocol, you can think of them as a set of attributes and methods that all objects satisfying the protocol have. Here, in the context of jsonschema, the Validator.iter_errors method can be called on jsonschema.validators.Draft202012Validator, or jsonschema.validators.Draft7Validator, or indeed any validator class, as all of them have it, along with all of the other methods described below.
๐ŸŒ
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.
๐ŸŒ
Ajv
ajv.js.org
Ajv JSON schema validator
It allows implementing complex data validation logic via declarative schemas for your JSON data, without writing code.
Find elsewhere
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ jsonschema
jsonschema - npm
January 7, 2025 - A fast and easy to use JSON Schema validator. Latest version: 1.5.0, last published: a year ago. Start using jsonschema in your project by running `npm i jsonschema`. There are 2520 other projects in the npm registry using jsonschema.
      ยป npm install jsonschema
    
Published ย  Jan 07, 2025
Version ย  1.5.0
Author ย  Tom de Grunt
๐ŸŒ
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%
๐ŸŒ
Google
developers.google.com โ€บ search central โ€บ schema markup testing tool | google search central
Schema Markup Testing Tool | Google Search Central | Google for Developers
Google recommends that you start with the Rich Results Test to see what Google rich results can be generated for your page. For generic schema validation, use the Schema Markup Validator to test all types of schema.org markup, without Google-specific validation.
๐ŸŒ
GitHub
github.com โ€บ pboettch โ€บ json-schema-validator
GitHub - pboettch/json-schema-validator: JSON schema validator for JSON for Modern C++ ยท GitHub
JSON schema validator for JSON for Modern C++. Contribute to pboettch/json-schema-validator development by creating an account on GitHub.
Starred by 604 users
Forked by 154 users
Languages ย  C++ 86.2% | CMake 12.3% | Python 1.3% | Shell 0.2%
๐ŸŒ
Jsonschemalint
jsonschemalint.com
JSON Schema Lint
Error: This application requires JavaScript to run. Please enable JavaScript to continue
๐ŸŒ
GitHub
github.com โ€บ voxpupuli โ€บ json-schema
GitHub - voxpupuli/json-schema: Ruby JSON Schema Validator ยท GitHub
This library is intended to provide Ruby with an interface for validating JSON objects against a JSON schema conforming to JSON Schema Draft 6.
Starred by 1.6K users
Forked by 248 users
Languages ย  Ruby
๐ŸŒ
Apache Camel
camel.apache.org โ€บ apache camel โ€บ camel components โ€บ 4.18.x (lts) โ€บ components โ€บ json schema validator
JSON Schema Validator :: Apache Camel
The JSON Schema Validator component performs bean validation of the message body against JSON Schemas v4, v6, v7, v2019-09 draft and v2020-12(partial) using the NetworkNT JSON Schema library (https://github.com/networknt/json-schema-validator).
๐ŸŒ
Rust
docs.rs โ€บ jsonschema
jsonschema - Rust
For better performance, especially when validating multiple instances against the same schema, build a validator once and reuse it: If your schema contains external references, you can choose between blocking and non-blocking construction: use serde_json::json; let schema = json!({"type": "string"}); // Blocking construction - will fetch external references synchronously let validator = jsonschema::validator_for(&schema)?; // Non-blocking construction - will fetch external references asynchronously let validator = jsonschema::async_validator_for(&schema).await?; // Once constructed, validation
Top answer
1 of 3
4

As far as the code is concerned, you're doing it right, and you don't need the ValidateMetaSchema option. That option validates the schema against its metaschema while you're validating other JSON data against the schema.

For example, if I have deserialized your last example

{
  "$schema": ""http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": [
    "prop1",
    "prop2",
    "prop3",
    "prop4",
    "prop5", 
    "prop6"
  ]
}

into JsonSchema and I'm using that to validate some other JSON data, then that option will add a secondary validation of the schema against the draft 7 metaschema. If the schema is invalid for some reason (for example, in draft 7 "$defs": 42 would be ignored, but draft 2020-12 it's invalid), then the $schema keyword would raise an error that would be included in the output.

In your case, you'd be directly validating the draft 7 metaschema against its metaschema (which is just itself). But we already know that the draft 7 metaschema is valid against itself, so this is just an extra check that's unnecessary. Go ahead and leave that option off.


In a comment, you asked if there was a way to raise an error if unknown keywords were present. There is no such option.

However, what you can do is check the schema.Keywords property for any that are of type UnrecognizedKeyword. If there are any, then you have extra data in the schema.

Be mindful that schemas can nest, though, so you'll need to check each level.

{
  "allOf": [
    { "unrecognized": "keyword" }
  ]
}

Here, you'll need to go find the AllOfKeyword and check its subschemas for UnrecognizedKeywords.


Aside from that, I'm going to expand on @Clemens' answer a bit to explain why your examples are coming back as valid.

{
  "f": "a"
}

When validated against a metaschema, this JSON is going to produce the same validation result as your second example {} because (as @Clemens mentioned) JSON Schema ignores unknown keywords. Since f isn't a recognized keyword, it's ignored by validation. (There's an annotation collected for f the output, though.)

Because this has no validation keywords in it, it will validate all JSON instances. Technically this is a valid schema, although it doesn't do much.

{
  "required": [
    "prop1",
    "prop2",
    "prop3",
    "prop4",
    "prop5",
    "prop6"
  ]
}

Here, you're requiring certain properties to be present if the JSON instance is an object. But if the instance is not an object, required has no effect. You'll probably want to constrain values more with "type": "object".

{
  "$schema": ""http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": [
    "prop1",
    "prop2",
    "prop3",
    "prop4",
    "prop5", 
    "prop6"
  ]
}

Here you have all the pieces in place, and what you probably expect can work. The JSON is still a valid draft 7 schema (it's also valid for draft 2020-12).

In order for the schema to be invalid, you'd have to put a valid in for a defined keyword that it doesn't support, like giving maximum a string value. In this case, the schema will fail validation.

That said, if you were to try to deserialize invalid schema JSON into a JsonSchema model, the serializer will throw an exception because there's some validation that occurs during deserialization.

I think your approach of validating the schema JSON against a meta-schema is better than letting the serializer throw an exception, but you'll want to be sure you validate against the metaschema that's represented in the $schema keyword. (So don't validate a draft 2020-12 schema against the draft 7 metaschema.)

2 of 3
3

Your examples are not covered by validation against the meta schemas. The meta schemas use an open model and there is also no semantic checking. You would need a JSON schema linter like the one coming with JSONBuddy (https://www.json-buddy.com), also available at json-schema-linter.com for quick testing.

๐ŸŒ
jsonschema
python-jsonschema.readthedocs.io
jsonschema 4.26.0 documentation
Programmatic querying of which properties or items failed validation. jsonschema is available on PyPI. You can install using pip: ... Be aware that the mere presence of these dependencies โ€“ or even the specification of format checks in a schema โ€“ do not activate format checks (as per the specification).