logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    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.

    Inheritance
    object
    JsonValue
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    Namespace: Serenity.StructuredPersistence.Infrastructure.Json
    Assembly: Serenity.StructuredPersistence.Json.dll
    Syntax
    public sealed class JsonValue

    Properties

    Kind

    Declaration
    public JsonValueKind Kind { get; }
    Property Value
    Type Description
    JsonValueKind

    Methods

    AsBool()

    Gets this value as a bool.

    Declaration
    public bool AsBool()
    Returns
    Type Description
    bool
    Exceptions
    Type Condition
    JsonParseException

    Thrown when this value is not a boolean.

    AsDouble()

    Gets this value as a double.

    Declaration
    public double AsDouble()
    Returns
    Type Description
    double
    Exceptions
    Type Condition
    JsonParseException

    Thrown when this value is not a number.

    AsInt()

    Gets this value as an int.

    Declaration
    public int AsInt()
    Returns
    Type Description
    int

    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
    Type Description
    long
    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
    Type Description
    string
    Exceptions
    Type Condition
    JsonParseException

    Thrown when this value is neither a string nor null.

    GetItems()

    Gets the elements of a JSON array.

    Declaration
    public IReadOnlyList<JsonValue> GetItems()
    Returns
    Type Description
    IReadOnlyList<JsonValue>
    Exceptions
    Type Condition
    JsonParseException

    Thrown when this value is not an array.

    GetProperty(string)

    Gets a required property from a JSON object.

    Declaration
    public JsonValue GetProperty(string name)
    Parameters
    Type Name Description
    string name
    Returns
    Type Description
    JsonValue
    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
    Type Description
    IReadOnlyDictionary<string, JsonValue>
    Exceptions
    Type Condition
    JsonParseException

    Thrown when this value is not an object.

    Parse(string)

    Parses json into a JsonValue tree.

    Declaration
    public static JsonValue Parse(string json)
    Parameters
    Type Name Description
    string json
    Returns
    Type Description
    JsonValue
    Exceptions
    Type Condition
    JsonParseException

    Thrown when json is not valid JSON.

    In this article
    © 2026 Serenity. All Rights Reserved