Skip to content

Json Class ​

Definition ​

Wrapper class for standardized JSON Serialization and Deserialization

  • Namespace: JASE.Serializers
  • Assembly: JASE.Serializers.dll

Properties ​

NameDescription
CamelCasePropertiesGet current setting for camelCasing property names
CaseInsensitivePropertiesGet current setting for case insensitive property
ErrorOnMissingMembersGet how missing members are handled during Deserialization
GuidNoHyphenWhen true Guid's are Serialized without a hyphen
IgnoreNullsGet how values are handled during Serialization and Deserialization
PrettyPrintControls the identation of Serialized JSON result
SuppressEmptyGuidWhen true, Guid.Empty values are sent as null

Methods ​

NameDescription
T ConvertObject(JsonElement element, JsonSerializerOptions options = null)Convert a JsonElement to the requested type.
T ConvertObject(JsonElement element, string propertyName, JsonSerializerOptions options = null)Convert a named property of a JsonElement to the requested type.
object ConvertObject(JsonElement element, Type type, JsonSerializerOptions options = null)Convert a JsonElement to the requested type.
T Copy(object input)Copies an instance of an object by Serializing and Deserializing using System.Text.Json
bool DeepEquals(JsonDocument a, JsonDocument b)Determines whether two JsonDocument instances are structurally deeply equal.
bool DeepEquals(JsonElement a, JsonElement b)Performs a deep structural comparison of two JsonElement values.
bool DeepEquals(string a, string b)Determines whether two JSON payloads are deeply equal.
T Deserialize(Stream json, JsonSerializerOptions options = null)Deserialize JSON from a Stream into an object of type T.
T Deserialize(byte[] json, JsonSerializerOptions options = null)Deserialize a JSON byte[] into an object type
T Deserialize(string json, JsonSerializerOptions options = null)Deserialize a JSON string into an object type
object Deserialize(Stream json, Type type, JsonSerializerOptions options = null)Deserialize JSON from a Stream into an object of the specified type.
object Deserialize(byte[] json, Type type, JsonSerializerOptions options = null)Deserialize a JSON byte[] into an object type
object Deserialize(string json, Type type, JsonSerializerOptions options = null)Deserialize a JSON string into an object type
Task<T> DeserializeAsync(Stream json, JsonSerializerOptions options = null, CancellationToken cancellationToken = null)Asynchronously deserialize JSON from a Stream into an object of type T.
Task<object> DeserializeAsync(Stream json, Type type, JsonSerializerOptions options = null, CancellationToken cancellationToken = null)Asynchronously deserialize JSON from a Stream into an object of the specified type.
JsonDocumentOptions GetDocumentOptionsClone()Return current instance of JsonDocumentOptions used for JSON parsing.
JsonSerializerOptions GetInboundApiOptionsClone()Returns a clone of the default serializer options with inbound single-or-array list leniency enabled.
JsonElement GetObject(byte[] json)Parses a UTF8 byte array into a JsonElement, explicitly verifying it is an object.
JsonElement GetObject(string json)Parses a string into a JsonElement, explicitly verifying it is an object.
JsonSerializerOptions GetOptionsClone()Return current instance of JsonSerializerOptions settings
bool IsJsonArray(byte[] json)Returns TRUE is the input JSON is an Array
bool IsJsonArray(string json)Returns TRUE is the input JSON is an Array
bool IsJsonObject(byte[] json)Returns TRUE is the input JSON is an Object
bool IsJsonObject(string json)Returns TRUE is the input JSON is an Object
bool IsValidJson(string json)Returns when json is a valid JSON object or array.
string Merge(string original, string transformJson)Merges a transform JSON into an original JSON, applying transformations such as adding or replacing properties.
void Populate(T target, string json, JsonSerializerOptions options = null, JsonObjectPopulateMode mode = null, JsonNullHandling nullHandling = null)Populates an existing instance of T with values from a JSON object payload.
void Populate(object target, byte[] json, JsonSerializerOptions options = null, JsonObjectPopulateMode mode = null, JsonNullHandling nullHandling = null)Populates an existing object instance with values from a UTF-8 encoded JSON object payload.
void Populate(object target, string json, JsonSerializerOptions options = null, JsonObjectPopulateMode mode = null, JsonNullHandling nullHandling = null)Populates an existing object instance with values from a JSON object payload.
string Prettify(string json)Convert input JSON to Prettified version
string Serialize(object input, JsonSerializerOptions options = null)Returns JSON serialized string
string Serialize(object input, Type type, JsonSerializerOptions options = null)Returns JSON serialized string
byte[] SerializeToUtf8Bytes(object input, JsonSerializerOptions options = null)Returns JSON string converted to a UTF-8 byte[]
byte[] SerializeToUtf8Bytes(object input, Type type, JsonSerializerOptions options = null)Returns JSON string converted to a UTF-8 byte[]
void SetCamelCaseProperties(bool value)Manage setting for camelCasing properties in serialized data
void SetCaseInsensitiveProperties(bool value)Manage setting for Case Insensitive propery names when deserializing json
void SetGuidNoHyphen(bool value)Manage serialized output of Guid values containing hypens or not
void SetIgnoreNulls(bool value)Manage serialized output as including nulls or not
void SetPrettyPrint(bool value)Manage serialized output as indented (true) or not (false)
void SetSuppressEmptyGuid(bool value)Manage serialized output of Guid.Empty values being sent or not
bool TryDeserialize(ReadOnlySpan<byte> json, out T output, JsonSerializerOptions options = null)Attempts to deserialize JSON bytes into a T without throwing.
bool TryDeserialize(byte[] json, Type type, out object output, JsonSerializerOptions options = null)Deserialize a JSON string into an object type
bool TryDeserialize(string json, Type type, out object output, JsonSerializerOptions options = null)Deserialize a JSON string into an object type
bool TryDeserialize(string json, out T output, JsonSerializerOptions options = null)Attempts to deserialize JSON into a T without throwing.
string UncommentJson(string json)Sanitizes input string to ensure that it does not contain comment lines