Class JsonSchema
- Namespace
- Nerdbank.Json
- Assembly
- Nerdbank.Json.dll
A minimal, ordered JSON object model used to build JSON Schema documents without rooting
System.Text.Json.
public sealed class JsonSchema
- Inheritance
-
JsonSchema
- Inherited Members
Remarks
An empty schema (no keywords) matches any JSON value. Use the Set(string, string) family of methods to add schema keywords, and ToString() or JsonSerializer integration to serialize. Keyword order is preserved for deterministic output.
Constructors
JsonSchema()
Initializes a new instance of the JsonSchema class that matches any value.
public JsonSchema()
Methods
Set(string, JsonSchema)
Sets a nested-schema keyword (for example items).
public JsonSchema Set(string keyword, JsonSchema value)
Parameters
keywordstringThe keyword name.
valueJsonSchemaThe nested schema.
Returns
- JsonSchema
This instance.
Set(string, bool)
Sets a boolean-valued keyword.
public JsonSchema Set(string keyword, bool value)
Parameters
Returns
- JsonSchema
This instance.
Set(string, double)
Sets a floating-point keyword.
public JsonSchema Set(string keyword, double value)
Parameters
Returns
- JsonSchema
This instance.
Set(string, long)
Sets an integer-valued keyword.
public JsonSchema Set(string keyword, long value)
Parameters
Returns
- JsonSchema
This instance.
Set(string, string)
Sets a string-valued keyword.
public JsonSchema Set(string keyword, string value)
Parameters
Returns
- JsonSchema
This instance.
SetIntegers(string, IReadOnlyList<long>)
Sets a keyword whose value is an array of integers (for example enum).
public JsonSchema SetIntegers(string keyword, IReadOnlyList<long> value)
Parameters
keywordstringThe keyword name.
valueIReadOnlyList<long>The integer array.
Returns
- JsonSchema
This instance.
SetMap(string, IReadOnlyList<KeyValuePair<string, JsonSchema>>)
Sets a keyword whose value is an ordered map of names to schemas (for example properties).
public JsonSchema SetMap(string keyword, IReadOnlyList<KeyValuePair<string, JsonSchema>> value)
Parameters
keywordstringThe keyword name.
valueIReadOnlyList<KeyValuePair<string, JsonSchema>>The ordered map.
Returns
- JsonSchema
This instance.
SetSchemas(string, IReadOnlyList<JsonSchema>)
Sets a keyword whose value is an array of schemas (for example oneOf or prefixItems).
public JsonSchema SetSchemas(string keyword, IReadOnlyList<JsonSchema> value)
Parameters
keywordstringThe keyword name.
valueIReadOnlyList<JsonSchema>The schema array.
Returns
- JsonSchema
This instance.
SetStrings(string, IReadOnlyList<string>)
Sets a keyword whose value is an array of strings (for example required or enum).
public JsonSchema SetStrings(string keyword, IReadOnlyList<string> value)
Parameters
keywordstringThe keyword name.
valueIReadOnlyList<string>The string array.
Returns
- JsonSchema
This instance.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.