VOOZH about

URL: https://www.nuget.org/packages/JsonStructure

⇱ NuGet Gallery | JsonStructure 0.7.0




👁 Image
JsonStructure 0.7.0

dotnet add package JsonStructure --version 0.7.0
 
 
NuGet\Install-Package JsonStructure -Version 0.7.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="JsonStructure" Version="0.7.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JsonStructure" Version="0.7.0" />
 
Directory.Packages.props
<PackageReference Include="JsonStructure" />
 
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 JsonStructure --version 0.7.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: JsonStructure, 0.7.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 JsonStructure@0.7.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=JsonStructure&version=0.7.0
 
Install as a Cake Addin
#tool nuget:?package=JsonStructure&version=0.7.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

JSON Structure C# SDK

A comprehensive C# SDK for JSON Structure validation, including schema validation, instance validation, schema export from .NET types, and System.Text.Json converters for correct serialization of large numeric types.

Features

  • Schema Validation: Validate JSON Structure schema documents
  • Instance Validation: Validate JSON instances against JSON Structure schemas
  • Schema Export: Generate JSON Structure schemas from .NET types (similar to System.Text.Json.Schema.JsonSchemaExporter)
  • System.Text.Json Converters: Serialize large integers (int64, uint64, int128, uint128, decimal) as strings to preserve precision

Installation

dotnet add package JsonStructure

Usage

Schema Validation

using JsonStructure.Validation;
using System.Text.Json.Nodes;

var validator = new SchemaValidator();

var schema = new JsonObject
{
 ["type"] = "object",
 ["properties"] = new JsonObject
 {
 ["name"] = new JsonObject { ["type"] = "string" },
 ["age"] = new JsonObject { ["type"] = "int32" }
 },
 ["required"] = new JsonArray { "name" }
};

var result = validator.Validate(schema);
if (result.IsValid)
{
 Console.WriteLine("Schema is valid!");
}
else
{
 foreach (var error in result.Errors)
 {
 Console.WriteLine($"{error.Path}: {error.Message}");
 }
}

Instance Validation

using JsonStructure.Validation;
using System.Text.Json.Nodes;

var validator = new InstanceValidator();

var schema = new JsonObject
{
 ["type"] = "object",
 ["properties"] = new JsonObject
 {
 ["name"] = new JsonObject { ["type"] = "string" },
 ["age"] = new JsonObject { ["type"] = "int32", ["minimum"] = 0 }
 },
 ["required"] = new JsonArray { "name" }
};

var instance = new JsonObject
{
 ["name"] = "John",
 ["age"] = 30
};

var result = validator.Validate(instance, schema);
if (result.IsValid)
{
 Console.WriteLine("Instance is valid!");
}

Sideloading External Schemas

When using $import to reference external schemas, you can provide those schemas directly instead of fetching them from URIs:

using JsonStructure.Validation;
using System.Text.Json.Nodes;

// External schema that would normally be fetched
var addressSchema = new JsonObject
{
 ["$schema"] = "https://json-structure.org/meta/core/v0/#",
 ["$id"] = "https://example.com/address.json",
 ["type"] = "object",
 ["properties"] = new JsonObject
 {
 ["street"] = new JsonObject { ["type"] = "string" },
 ["city"] = new JsonObject { ["type"] = "string" }
 }
};

// Main schema that imports the address schema
var mainSchema = new JsonObject
{
 ["$schema"] = "https://json-structure.org/meta/core/v0/#",
 ["type"] = "object",
 ["properties"] = new JsonObject
 {
 ["name"] = new JsonObject { ["type"] = "string" },
 ["address"] = new JsonObject { ["$ref"] = "#/definitions/Imported/Address" }
 },
 ["definitions"] = new JsonObject
 {
 ["Imported"] = new JsonObject
 {
 ["$import"] = "https://example.com/address.json"
 }
 }
};

// Sideload the address schema - keyed by URI
var options = new ValidationOptions
{
 AllowImport = true,
 ExternalSchemas = new Dictionary<string, JsonNode>
 {
 ["https://example.com/address.json"] = addressSchema
 }
};

var validator = new SchemaValidator(options);
var result = validator.Validate(mainSchema);

Schema Export from .NET Types

Generate JSON Structure schemas from C# classes:

using JsonStructure.Schema;
using System.ComponentModel.DataAnnotations;

public class Person
{
 [Required]
 [StringLength(100, MinimumLength = 1)]
 public string Name { get; set; } = "";

 [Range(0, 150)]
 public int Age { get; set; }

 public List<string> Tags { get; set; } = new();

 public Dictionary<string, int> Scores { get; set; } = new();
}

// Generate schema
var schema = JsonStructureSchemaExporter.GetJsonStructureSchemaAsNode<Person>();

// Output:
// {
// "$schema": "https://json-structure.org/meta/core/v1.0",
// "type": "object",
// "title": "Person",
// "properties": {
// "Name": { "type": "string", "minLength": 1, "maxLength": 100 },
// "Age": { "type": "int32", "minimum": 0, "maximum": 150 },
// "Tags": { "type": "array", "items": { "type": "string" } },
// "Scores": { "type": "map", "values": { "type": "int32" } }
// },
// "required": ["Name"]
// }

System.Text.Json Converters

Use the converters to correctly serialize large integers as strings (avoiding JavaScript precision issues):

using JsonStructure.Converters;
using System.Text.Json;

// Create options with all JSON Structure converters
var options = JsonStructureConverters.CreateOptions();

// Or add to existing options
var existingOptions = new JsonSerializerOptions();
JsonStructureConverters.ConfigureOptions(existingOptions);

// Now large numbers are serialized as strings
var data = new { BigNumber = 9007199254740993L };
var json = JsonSerializer.Serialize(data, options);
// Output: {"BigNumber":"9007199254740993"}

// Decimals are also serialized as strings for precision
var money = new { Amount = 12345.67890123456789m };
var moneyJson = JsonSerializer.Serialize(money, options);
// Output: {"Amount":"12345.67890123456789"}

Individual Converters

The SDK includes the following converters:

Converter Type Description
Int64StringConverter long Serializes int64 as string
UInt64StringConverter ulong Serializes uint64 as string
Int128StringConverter Int128 Serializes int128 as string
UInt128StringConverter UInt128 Serializes uint128 as string
DecimalStringConverter decimal Serializes decimal as string
DurationStringConverter TimeSpan Serializes as ISO 8601 duration
DateOnlyConverter DateOnly Serializes as RFC 3339 date
TimeOnlyConverter TimeOnly Serializes as RFC 3339 time
UuidStringConverter Guid Serializes as standard UUID format
UriStringConverter Uri Serializes as URI string
Base64BinaryConverter byte[] Serializes as base64 string

Supported Types

Primitive Types

JSON Structure Type .NET Type
string string
boolean bool
int8 sbyte
int16 short
int32 int
int64 long
int128 Int128
uint8 byte
uint16 ushort
uint32 uint
uint64 ulong
uint128 UInt128
float8 Half
float float
double double
decimal decimal
date DateOnly
time TimeOnly
datetime DateTime, DateTimeOffset
duration TimeSpan
uuid Guid
uri Uri
binary byte[], ReadOnlyMemory<byte>

Compound Types

JSON Structure Type .NET Type
object Class, struct
array List<T>, T[], IEnumerable<T>
set HashSet<T>, ISet<T>
map Dictionary<K,V>, IDictionary<K,V>
tuple (via prefixItems)
choice (via options and discriminator)

Validation Options

var options = new ValidationOptions
{
 StopOnFirstError = false, // Continue collecting all errors
 StrictFormatValidation = true, // Validate format keywords strictly
 MaxValidationDepth = 100, // Maximum schema nesting depth
 AllowImport = true, // Enable $import/$importdefs processing
 ExternalSchemas = new Dictionary<string, JsonNode>
 {
 // Sideloaded schemas for import resolution (keyed by URI)
 ["https://example.com/address.json"] = addressSchema
 },
 ReferenceResolver = uri => // Custom $ref resolver
 {
 // Return resolved schema or null
 return null;
 }
};

var validator = new InstanceValidator(options);

Schema Export Options

var exporterOptions = new JsonStructureSchemaExporterOptions
{
 SchemaUri = "https://json-structure.org/meta/core/v1.0",
 IncludeSchemaKeyword = true,
 IncludeTitles = true,
 IncludeDescriptions = true,
 TreatNullObliviousAsNonNullable = true,
 TransformSchema = (context, schema) =>
 {
 // Custom schema transformation
 if (context.IsRoot && schema is JsonObject obj)
 {
 obj["$id"] = "https://example.com/my-schema";
 }
 return schema;
 }
};

var schema = JsonStructureSchemaExporter.GetJsonStructureSchemaAsNode<MyClass>(
 exporterOptions: exporterOptions);

License

MIT License. See for details.

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

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.7.0 56 6/8/2026
0.6.2 62 6/4/2026
0.6.1 86 3/24/2026
0.6.0 280 1/27/2026
0.5.5 416 12/9/2025
0.5.3 408 12/9/2025
0.5.2 403 12/9/2025
0.5.1 406 12/9/2025
0.5.0 409 12/9/2025
0.4.1 167 12/4/2025
0.4.0 166 12/4/2025
0.3.0 642 12/2/2025
0.2.0 641 12/1/2025
0.1.21 547 12/1/2025
0.1.20 557 12/1/2025
0.1.19 324 11/30/2025
0.1.18 233 11/30/2025
0.1.16 86 11/29/2025
0.1.15 90 11/29/2025
0.1.14 95 11/29/2025
Loading failed