JsonArray.ReadOnly
Namespace: SnowBank.Data.Json · class
Operations for read-only JSON arrays
Methods
Create
static JsonArray Create()
Returns a read-only empty array, that cannot be modified
This method will always return Empty singleton.
For a mutable array, see Create
static JsonArray Create(JsonValue value)
Creates a new read-onlyJSON Array with a single element
For a mutable array, see
static JsonArray Create(params JsonValue[] values)
Create a new read-onlyJSON Array from an array of elements
For a mutable array, see
static JsonArray Create(ReadOnlySpan<JsonValue> values)
Create a new read-onlyJSON Array from a span of elements
For a mutable array, see
static JsonArray Create(IEnumerable<JsonValue> values)
Create a new read-onlyJSON Array from a sequence of elements
For a mutable array, see
static JsonArray Create(JsonValue value1, JsonValue value2)
Create a new read-onlyJSON Array with 2 elements
For a mutable array, see
static JsonArray Create(JsonValue value1, JsonValue value2, JsonValue value3)
Create a new read-onlyJSON Array with 3 elements
For a mutable array, see
static JsonArray Create(JsonValue value1, JsonValue value2, JsonValue value3, JsonValue value4)
Create a new read-onlyJSON Array with 4 elements
For a mutable array, see
FromValues
static JsonArray FromValues<TValue>(ReadOnlySpan<TValue> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)
Creates a new read-only JSON Array from a span of raw values.
values— Span of values that must be convertedsettings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Immutable JSON Array with all values converted into read-onlyJsonValue instances.
For a mutable array, see
static JsonArray FromValues<TValue>(TValue[] values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)
Creates a new read-only JSON Array from an array of raw values.
values— Array of values that must be convertedsettings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Immutable JSON Array with all values converted into read-onlyJsonValue instances.
For a mutable array, see
static JsonArray FromValues<TValue>(IEnumerable<TValue> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)
Creates a new read-only JSON Array from a sequence of raw values.
values— Sequence of values that must be convertedsettings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Immutable JSON Array with all values converted into read-onlyJsonValue instances.
For a mutable array, see
static JsonArray FromValues(ReadOnlySpan<string> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)
Creates a new mutable JSON Array from a span of string literals.
values— Span of values that must be convertedsettings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Mutable array with all values converted into JsonValue instances
For a read-only array, see
static JsonArray FromValues(ReadOnlySpan<int> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)
Creates a new mutable JSON Array from a span of numbers.
values— Span of values that must be convertedsettings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Mutable array with all values converted into JsonValue instances
For a read-only array, see
static JsonArray FromValues(ReadOnlySpan<long> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)
Creates a new mutable JSON Array from a span of numbers.
values— Span of values that must be convertedsettings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Mutable array with all values converted into JsonValue instances
For a read-only array, see
static JsonArray FromValues(ReadOnlySpan<float> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)
Creates a new mutable JSON Array from a span of numbers.
values— Span of values that must be convertedsettings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Mutable array with all values converted into JsonValue instances
For a read-only array, see
static JsonArray FromValues(ReadOnlySpan<double> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)
Creates a new mutable JSON Array from a span of numbers.
values— Span of values that must be convertedsettings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Mutable array with all values converted into JsonValue instances
For a read-only array, see
static JsonArray FromValues(ReadOnlySpan<Guid> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)
Creates a new mutable JSON Array from a span of Guid.
values— Span of values that must be convertedsettings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Mutable array with all values converted into JsonValue instances
For a read-only array, see
static JsonArray FromValues(ReadOnlySpan<Uuid128> values, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)
Creates a new mutable JSON Array from a span of Uuid128.
values— Span of values that must be convertedsettings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Mutable array with all values converted into JsonValue instances
For a read-only array, see
static JsonArray FromValues<TItem, TValue>(ReadOnlySpan<TItem> values, Func<TItem, TValue> selector, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)
Creates a new read-only JSON Array with values extracted from a span of source items.
values— Span of items to convertselector— Lambda that will extract a value from each item in the source.settings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Immutable JSON Array with all values converted into read-onlyJsonValue instances.
For a mutable array, see
static JsonArray FromValues<TItem, TValue>(TItem[] values, Func<TItem, TValue> selector, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)
Creates a new read-only JSON Array with values extracted from an array of source items.
values— Array of items to convertselector— Lambda that will extract a value from each item in the source.settings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Immutable JSON Array with all values converted into read-onlyJsonValue instances.
For a mutable array, see
static JsonArray FromValues<TItem, TValue>(IEnumerable<TItem> values, Func<TItem, TValue> selector, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)
Creates a new read-only JSON Array with values extracted from a sequence of source items.
values— Sequence of items to convertselector— Lambda that will extract a value from each item in the source.settings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Immutable JSON Array with all values converted into read-onlyJsonValue instances.
For a mutable array, see
Parse
static JsonArray Parse(string jsonText, CrystalJsonSettings settings = null)
Parses a JSON text literal that is expected to contain an Array, as a read-only JSON array
jsonText— JSON text document to parsesettings— Serialization settings (use default JSON settings if null)
Returns: Corresponding immutable JSON Array. If jsonText is empty or not an Array, an exception will be thrown instead.
The JSON Array is immutable and cannot be modified. If you require a mutable array, please use ParseArray instead.
If the JSON document can sometimes be empty of the 'null' token, you should call Parse and then use AsArrayOrDefault on the result.
static JsonArray Parse(ReadOnlySpan<char> jsonText, CrystalJsonSettings settings = null)
Parses a JSON text literal that is expected to contain an Array, as a read-only JSON array
jsonText— JSON text document to parsesettings— Serialization settings (use default JSON settings if null)
Returns: Corresponding immutable JSON Array. If jsonText is empty or not an Array, an exception will be thrown instead.
The JSON Array is immutable and cannot be modified. If you require a mutable array, please use ParseArray instead.
If the JSON document can sometimes be empty of the 'null' token, you should call Parse and then use AsArrayOrDefault on the result.
static JsonArray Parse(ReadOnlySpan<byte> jsonBytes, CrystalJsonSettings settings = null)
Parses a buffer containing a document that is expected to be an Array
jsonBytes— UTF-8 encoded bytessettings— Serialization settings (use default JSON settings if null)
Returns: Corresponding JSON Array. If jsonBytes is empty or not an Array, an exception will be thrown
The resulting Array is immutable and cannot be modified. If you require a mutable array, please use ParseArray instead.
If the JSON document can sometimes be empty of the 'null' token, you should call Parse and then use AsArrayOrDefault on the result.
static JsonArray Parse(Slice jsonBytes, CrystalJsonSettings settings = null)
Parses a buffer containing a UTF-8 encoded JSON Array
jsonBytes— UTF-8 encoded bytessettings— Serialization settings (use default JSON settings if null)
Returns: Corresponding readonly JSON Array. If jsonBytes is null or empty, will return Missing
Fields
Empty
static readonly JsonArray Empty
Returns an empty, read-only, JSON Array singleton
This instance cannot be modified, and should be used to reduce memory allocations when working with read-only JSON