JsonValue.ReadOnly
Namespace: SnowBank.Data.Json · class
Operations for read-only JSON values
Methods
FromValue
static JsonValue FromValue(object value)
Converts a boxed instance into a read-only JSON value
value— Instance to convert (primitive, class, struct, array, ...)
Returns: Corresponding JSON value(JsonNumber, JsonObject, JsonArray, ...), or Null if value is null
Consider using instead, if the type is known at compile time, in order to reduce runtime overhead.
static JsonValue FromValue<T>(T value)
Converts a typed value into a read-only JSON value
value— Instance to convert
Returns: Corresponding JSON value(JsonNumber, JsonObject, JsonArray, ...), or Null if value is null
static JsonValue FromValue(object value, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver = null)
Converts a boxed instance into a read-only JSON value
value— Instance to convert (primitive, class, struct, array, ...)settings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Corresponding JSON value(JsonNumber, JsonObject, JsonArray, ...), or Null if value is null
Consider using instead, if the type is known at compile time, in order to reduce runtime overhead.
static JsonValue FromValue<T>(T value, CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver = null)
Converts a typed value into a read-only JSON value
value— Instance to convertsettings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Corresponding JSON value(JsonNumber, JsonObject, JsonArray, ...), or Null if value is null
static JsonValue FromValue(object value, Type declaredType, CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)
Converts a boxed instance into a read-only JSON value
value— Instance to convert (primitive, class, struct, array, ...)declaredType— Type of the field in the parent container that points to this value (can be a base class or interface)settings— Serialization settings (use default JSON settings if null)resolver— Optional custom resolver used to bind the value into a managed type.
Returns: Corresponding JSON value(JsonNumber, JsonObject, JsonArray, ...), or Null if value is null
Consider using instead, if the type is known at compile time, in order to reduce runtime overhead.
Parse
static JsonValue Parse(string jsonText, CrystalJsonSettings settings = null)
Parses a JSON text literal, and returns the corresponding JSON value
jsonText— JSON text document to parsesettings— Serialization settings (use default JSON settings if null)
Returns: Corresponding JSON value. If jsonText is empty, will return Missing
The value will be immutable and cannot be modified. If you require a mutable value, please use Parse instead.
If the result is always expected to be an Array or an Object, please call either ParseArray or ParseObject.
static JsonValue Parse(ReadOnlySpan<char> jsonText, CrystalJsonSettings settings = null)
Parses a JSON text literal, and returns the corresponding JSON value
jsonText— JSON text document to parsesettings— Serialization settings (use default JSON settings if null)
Returns: Corresponding JSON value. If jsonText is empty, will return Missing
The value will be immutable and cannot be modified. If you require a mutable value, please use Parse instead.
If the result is always expected to be an Array or an Object, please call either ParseArray or ParseObject.
static JsonValue Parse(ReadOnlySpan<byte> jsonBytes, CrystalJsonSettings settings = null)
Parses a buffer containing a document
jsonBytes— UTF-8 encoded bytessettings— Serialization settings (use default JSON settings if null)
Returns: Corresponding read-only JSON value. If jsonBytes is null or empty, will return Missing
static JsonValue Parse(Slice jsonBytes, CrystalJsonSettings settings = null)
Parses a buffer containing a document
ParseArray
static JsonArray ParseArray(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 ParseArray(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 ParseArray(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 ParseArray(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
ParseObject
static JsonObject ParseObject(string jsonText, CrystalJsonSettings settings = null)
Parse a string literal containing a JSON Object
jsonText— Input text to parsesettings— Serialization settings (use default JSON settings if null)
Returns: Corresponding JSON Object. If jsonText is empty or not an object, an exception will be thrown instead.
The JSON object that is returned is immutable, and is safe for use as a singleton, a cached document, or for multithreaded operations. If you require a mutable version, please call
static JsonObject ParseObject(ReadOnlySpan<char> jsonText, CrystalJsonSettings settings = null)
Parse a string literal containing a JSON Object
jsonText— Input text to parsesettings— Serialization settings (use default JSON settings if null)
Returns: Corresponding JSON Object. If jsonText is empty or not an object, an exception will be thrown instead.
The JSON object that is returned is immutable, and is safe for use as a singleton, a cached document, or for multithreaded operations. If you require a mutable version, please call
static JsonObject ParseObject(ReadOnlySpan<byte> jsonBytes, CrystalJsonSettings settings = null)
Parses a buffer containing a document that is expected to be an Object
jsonBytes— UTF-8 encoded bytessettings— Serialization settings (use default JSON settings if null)
Returns: Corresponding immutable JSON Object. If jsonBytes is empty or not an Array, an exception will be thrown
The resulting object is immutable and cannot be modified. If you require a mutable array, please use ParseObject instead.
static JsonObject ParseObject(Slice jsonBytes, CrystalJsonSettings settings = null)
Parses a buffer containing a UTF-8 encoded JSON Object
jsonBytes— UTF-8 encoded bytessettings— Serialization settings (use default JSON settings if null)
Returns: Corresponding readonly JSON Object. If jsonBytes is null or empty, will return Missing