![]() |
VOOZH | about |
dotnet add package JsonStructure --version 0.7.0
NuGet\Install-Package JsonStructure -Version 0.7.0
<PackageReference Include="JsonStructure" Version="0.7.0" />
<PackageVersion Include="JsonStructure" Version="0.7.0" />Directory.Packages.props
<PackageReference Include="JsonStructure" />Project file
paket add JsonStructure --version 0.7.0
#r "nuget: JsonStructure, 0.7.0"
#:package JsonStructure@0.7.0
#addin nuget:?package=JsonStructure&version=0.7.0Install as a Cake Addin
#tool nuget:?package=JsonStructure&version=0.7.0Install as a Cake Tool
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.
dotnet add package JsonStructure
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}");
}
}
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!");
}
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);
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"]
// }
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"}
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 |
| 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> |
| 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) |
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);
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);
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. |
This package is not used by any NuGet packages.
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 |