Class JsonValue
A parsed JSON value produced by a minimal, dependency-free recursive-descent parser. Covers
exactly the JSON shapes needed to decode the structured-store wire/file payloads: objects,
arrays, strings, numbers, booleans, and null. Nesting beyond
Serenity.StructuredPersistence.Infrastructure.Json.JsonValue.MAX_PARSE_DEPTH levels is rejected so a hostile deeply-nested payload cannot
exhaust the stack.
Assembly: Serenity.StructuredPersistence.Json.dll
Syntax
public sealed class JsonValue
Properties
Kind
Declaration
public JsonValueKind Kind { get; }
Property Value
Methods
AsBool()
Gets this value as a bool.
Declaration
Returns
Exceptions
AsDouble()
Gets this value as a double.
Declaration
Returns
Exceptions
AsInt()
Gets this value as an int.
Declaration
Returns
AsLongFromDigitStringOrNumber()
Gets this value as a long. The canonical wire/file encoding is a QUOTED digit string (see
WriteQuotedLong(string, long) for why 64-bit integers are quoted, since a
bare JSON number is parsed into this double-backed representation, which only
exactly represents integers up to 2^53), but a bare JSON number is accepted leniently for
interoperability with producers that emit numbers — with the caveat that bare numbers above
2^53 may already have lost precision in transit.
Declaration
public long AsLongFromDigitStringOrNumber()
Returns
Exceptions
| Type |
Condition |
| JsonParseException |
Thrown when this value is neither a valid quoted integer string nor an integral JSON number in the 64-bit range.
|
AsStringOrNull()
Gets this value as a string, or null when this value is the JSON null literal.
Declaration
public string AsStringOrNull()
Returns
Exceptions
GetItems()
Gets the elements of a JSON array.
Declaration
public IReadOnlyList<JsonValue> GetItems()
Returns
Exceptions
GetProperty(string)
Gets a required property from a JSON object.
Declaration
public JsonValue GetProperty(string name)
Parameters
| Type |
Name |
Description |
| string |
name |
|
Returns
Exceptions
| Type |
Condition |
| JsonParseException |
Thrown when this value is not an object, or the property is missing.
|
GetPropertyMap()
Gets every property of a JSON object, keyed by property name. Unlike GetProperty(string)
(which requires the caller to already know the exact property name), this is for objects with
caller-chosen DYNAMIC keys — e.g. a structured record's field-name-to-value map — where the set
of names is only known by enumerating the object itself.
Declaration
public IReadOnlyDictionary<string, JsonValue> GetPropertyMap()
Returns
Exceptions
Parse(string)
Declaration
public static JsonValue Parse(string json)
Parameters
| Type |
Name |
Description |
| string |
json |
|
Returns
Exceptions