Philiprehberger.JsonSchema 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Philiprehberger.JsonSchema --version 0.1.0
                    
NuGet\Install-Package Philiprehberger.JsonSchema -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Philiprehberger.JsonSchema" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Philiprehberger.JsonSchema" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Philiprehberger.JsonSchema" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Philiprehberger.JsonSchema --version 0.1.0
                    
#r "nuget: Philiprehberger.JsonSchema, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Philiprehberger.JsonSchema@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Philiprehberger.JsonSchema&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Philiprehberger.JsonSchema&version=0.1.0
                    
Install as a Cake Tool

Philiprehberger.JsonSchema

CI NuGet License

Validate JSON documents against JSON Schema with structured error paths using System.Text.Json.

Installation

dotnet add package Philiprehberger.JsonSchema

Usage

using Philiprehberger.JsonSchema;

var schema = JsonSchema.Parse("""
{
    "type": "object",
    "properties": {
        "name": { "type": "string", "minLength": 1 },
        "age": { "type": "integer", "minimum": 0 }
    },
    "required": ["name"]
}
""");

var result = schema.Validate("""{ "name": "Alice", "age": 30 }""");
Console.WriteLine(result.IsValid); // True

Handling Validation Errors

var result = schema.Validate("""{ "age": -5 }""");

foreach (var error in result.Errors)
{
    Console.WriteLine($"{error.Path}: {error.Message} ({error.Keyword})");
    // $.name: Required property is missing (required)
    // $.age: Value is less than minimum of 0 (minimum)
}

Static Validation

var result = JsonSchema.Validate(schemaJson, documentJson);

API

Method Description
JsonSchema.Parse(string) Parse a JSON Schema string into a compiled schema
JsonSchema.Validate(string, string) Validate a JSON document against a schema string
Schema.Validate(string) Validate a JSON document against a compiled schema
Schema.Validate(JsonNode?) Validate a JsonNode against a compiled schema
ValidationResult.IsValid Whether validation passed
ValidationResult.Errors List of validation errors with paths

Development

dotnet build src/Philiprehberger.JsonSchema.csproj --configuration Release

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.1 122 4/1/2026
0.2.0 125 3/28/2026
0.1.1 113 3/23/2026
0.1.0 105 3/23/2026