JsonNumber

Namespace: SnowBank.Data.Json · class

Implements: JsonValue, IEquatable<JsonValue>, IComparable<JsonValue>, IJsonSerializable, IFormattable, ISliceSerializable, IConvertible, IParsable<JsonValue>, ISpanParsable<JsonValue>, ISpanFormattable, IUtf8SpanFormattable, INumberBase<JsonValue>, IUtf8SpanParsable<JsonValue>, IAdditionOperators<JsonValue, JsonValue, JsonValue>, IAdditiveIdentity<JsonValue, JsonValue>, IDecrementOperators<JsonValue>, IDivisionOperators<JsonValue, JsonValue, JsonValue>, IEqualityOperators<JsonValue, JsonValue, bool>, IIncrementOperators<JsonValue>, IMultiplicativeIdentity<JsonValue, JsonValue>, IMultiplyOperators<JsonValue, JsonValue, JsonValue>, ISubtractionOperators<JsonValue, JsonValue, JsonValue>, IUnaryNegationOperators<JsonValue, JsonValue>, IUnaryPlusOperators<JsonValue, JsonValue>, IComparisonOperators<JsonValue, JsonValue, bool>, IEquatable<JsonNumber>, IComparable<JsonNumber>, IEquatable<JsonString>, IEquatable<JsonBoolean>, IEquatable<JsonDateTime>, IEquatable<int>, IComparable<int>, IEquatable<long>, IComparable<long>, IEquatable<uint>, IComparable<uint>, IEquatable<ulong>, IComparable<ulong>, IEquatable<float>, IComparable<float>, IEquatable<double>, IComparable<double>, IEquatable<decimal>, IEquatable<short>, IEquatable<ushort>, IEquatable<TimeSpan>, IEquatable<Half>, IEquatable<Uuid48>, IEquatable<Int128>, IEquatable<UInt128>, INumberBase<JsonNumber>, IParsable<JsonNumber>, ISpanParsable<JsonNumber>, IUtf8SpanParsable<JsonNumber>, IAdditionOperators<JsonNumber, JsonNumber, JsonNumber>, IAdditiveIdentity<JsonNumber, JsonNumber>, IDecrementOperators<JsonNumber>, IDivisionOperators<JsonNumber, JsonNumber, JsonNumber>, IEqualityOperators<JsonNumber, JsonNumber, bool>, IIncrementOperators<JsonNumber>, IMultiplicativeIdentity<JsonNumber, JsonNumber>, IMultiplyOperators<JsonNumber, JsonNumber, JsonNumber>, ISubtractionOperators<JsonNumber, JsonNumber, JsonNumber>, IUnaryNegationOperators<JsonNumber, JsonNumber>, IUnaryPlusOperators<JsonNumber, JsonNumber>, IComparisonOperators<JsonNumber, long, bool>, IEqualityOperators<JsonNumber, long, bool>, IComparisonOperators<JsonNumber, ulong, bool>, IEqualityOperators<JsonNumber, ulong, bool>, IComparisonOperators<JsonNumber, float, bool>, IEqualityOperators<JsonNumber, float, bool>, IComparisonOperators<JsonNumber, double, bool>, IEqualityOperators<JsonNumber, double, bool>, IComparisonOperators<JsonNumber, decimal, bool>, IEqualityOperators<JsonNumber, decimal, bool>, IAdditionOperators<JsonNumber, long, JsonNumber>, IAdditionOperators<JsonNumber, ulong, JsonNumber>, IAdditionOperators<JsonNumber, float, JsonNumber>, IAdditionOperators<JsonNumber, double, JsonNumber>, IAdditionOperators<JsonNumber, decimal, JsonNumber>, ISubtractionOperators<JsonNumber, long, JsonNumber>, ISubtractionOperators<JsonNumber, ulong, JsonNumber>, ISubtractionOperators<JsonNumber, float, JsonNumber>, ISubtractionOperators<JsonNumber, double, JsonNumber>, ISubtractionOperators<JsonNumber, decimal, JsonNumber>, IMultiplyOperators<JsonNumber, long, JsonNumber>, IMultiplyOperators<JsonNumber, ulong, JsonNumber>, IMultiplyOperators<JsonNumber, float, JsonNumber>, IMultiplyOperators<JsonNumber, double, JsonNumber>, IMultiplyOperators<JsonNumber, decimal, JsonNumber>, IDivisionOperators<JsonNumber, long, JsonNumber>, IDivisionOperators<JsonNumber, ulong, JsonNumber>, IDivisionOperators<JsonNumber, float, JsonNumber>, IDivisionOperators<JsonNumber, double, JsonNumber>, IDivisionOperators<JsonNumber, decimal, JsonNumber>

JSON number

Properties

AdditiveIdentity

static JsonNumber AdditiveIdentity { get; }

Returns Zero

IsDecimal

bool IsDecimal { get; }

Returns true for decimal number (ex: "1.23", "123E-2"), or false for integers ("123", "1.23E10", ...)

It is possible, in some cases, that "2.0" would be considered a decimal number!

IsDefault

bool IsDefault { get; }

Tests if this value corresponds to the logical default for this type (0, false, null or missing, ...)

Returns: true for values like 0, false, or null; or false for non-zero integers, true, strings, arrays and objects

The empty string, array and object are NOT considered to be the default value of their type!

JsonNumber.Zero.IsDefault == true, JsonNumber.Return(123).IsDefault == false, JsonString.Return("").IsDefault == false, new JsonArray().IsDefault == false, new JsonObject().IsDefault == false

IsNegative

bool IsNegative { get; }

Returns true for negative numbers (ex: "-123", "-1.23"), or false for positive numbers ("0", "123", "1.23")

IsReadOnly

bool IsReadOnly { get; }

Returns true if this value is read-only, and cannot be modified, or false if it allows mutations.

Only JSON Objects and Arrays can return false. All other "value types" (string, boolean, numbers, ...) are always immutable, and will always be read-only.

If you need to modify a JSON Object or Array that is read-only, you should first create a copy, by calling either Copy or ToMutable, perform any changes required, and then either Freeze the copy, or call ToReadOnly again.

IsUnsigned

bool IsUnsigned { get; }

Returns true for positive integers (ex: "123"), or false for negative integers (ex: "-123") or decimal numbers (ex: "1.23")

Literal

string Literal { get; }

Returns the literal representation of the number (as it appeared in the original JSON document)

Could return "1.0" or "1", depending on the original format.

MinusOne

static JsonNumber MinusOne { get; }

-1 (signed int)

MultiplicativeIdentity

static JsonNumber MultiplicativeIdentity { get; }

Returns One

One

static JsonNumber One { get; }

1 (signed int)

Type

JsonType Type { get; }

Type of JSON value (Boolean, String, Number, Object, Array, ...)

Zero

static JsonNumber Zero { get; }

0 (signed int)

Methods

Abs

static JsonNumber Abs(JsonNumber value)

Bind

TValue Bind<TValue>(TValue defaultValue = null, ICrystalJsonTypeResolver resolver = null)

Bind this value into an instance of type TValue

  • defaultValue — Default value to return if the current instance is null or missing
  • resolver — Optional custom resolver used to bind the value into a managed type.

Returns: An instance of the type TValue that is equivalent to the original JSON value, if there exists a valid conversion path. Otherwise, an exception will be thrown.

JsonNumber.Return(123).Bind() will return the value 123.

object Bind(Type type, ICrystalJsonTypeResolver resolver = null)

Bind this value into an instance of the specified type

  • type — Target managed type
  • resolver — Optional custom resolver used to bind the value into a managed type.

Returns: An instance of the target type that is equivalent to the original JSON value, if there exists a valid conversion path or convention. Otherwise, an exception will be thrown.

If the target type is a Value Type, the instance will be boxed, which may cause extra memory allocations. Consider calling instance, or use any of the convenience methods like , , ...

JsonNumber.Return(123).Bind(typeof(long)) will return a boxed Int64 with value 123.

CompareTo

int CompareTo(JsonValue other)

Compares two JSON values, and returns an integer that indicates whether the first value precedes, follows, or occurs in the same position in the sort order as the second value.

int CompareTo(JsonNumber other)

int CompareTo(int value)

int CompareTo(long value)

int CompareTo(uint value)

int CompareTo(ulong value)

int CompareTo(float value)

int CompareTo(double value)

int CompareTo(JsonString other)

Create

static JsonValue Create(string value)

Returns the equivalent JsonNumber

static JsonValue Create(ReadOnlySpan<char> value)

Returns the equivalent JsonNumber

static JsonNumber Create(byte value)

Returns the equivalent JsonNumber

static JsonNumber Create(sbyte value)

Returns the equivalent JsonNumber

static JsonNumber Create(short value)

Returns the equivalent JsonNumber

static JsonNumber Create(ushort value)

Returns the equivalent JsonNumber

static JsonNumber Create(int value)

Returns the equivalent JsonNumber

  • value — Integer value

Returns: JSON value that will be serialized as an integer.

For small values a cached singleton is returned. For others values, a new instance will be allocated.

static JsonNumber Create(uint value)

Returns the equivalent JsonNumber

  • value — Integer value

Returns: JSON value that will be serialized as an integer.

For small values a cached singleton is returned. For others values, a new instance will be allocated.

static JsonNumber Create(long value)

Returns the equivalent JsonNumber

  • value — Integer value

Returns: JSON value that will be serialized as an integer.

For small values (between -128 and 255) a cached singleton is returned. For others values, a new instance will be allocated.

static JsonNumber Create(ulong value)

Returns the equivalent JsonNumber

  • value — Integer value

Returns: JSON value that will be serialized as an integer.

For small values (between 0 and 255) a cached singleton is returned. For others values, a new instance will be allocated.

static JsonNumber Create(double value)

Returns the equivalent JsonNumber

  • value — Decimal value

Returns: JSON value that will be serialized as a decimal value.

For , and NaN a cached singleton is returned. For others values, a new instance will be allocated.

static JsonNumber Create(float value)

Returns the equivalent JsonNumber

  • value — Decimal value

Returns: JSON value that will be serialized as a decimal value.

For , and NaN a cached singleton is returned. For others values, a new instance will be allocated.

static JsonNumber Create(Half value)

Returns the equivalent JsonNumber

  • value — Decimal value

Returns: JSON value that will be serialized as a decimal value.

For , and NaN a cached singleton is returned. For others values, a new instance will be allocated.

static JsonNumber Create(decimal value)

Returns the equivalent JsonNumber

static JsonNumber Create(Int128 value)

Returns the equivalent JsonNumber

static JsonNumber Create(UInt128 value)

Returns the equivalent JsonNumber

static JsonNumber Create(Uuid48 value)

Returns the equivalent JsonNumber

static JsonNumber Create(TimeSpan value)

Returns a JsonNumber corresponding to the number of seconds in the interval

  • value — Interval (in seconds)

Returns: JSON value that will be serialized as a decimal value.

Since TotalSeconds can introduce rounding errors, this value may not round-trip in all cases.

If an exact representation is required, please serialize the number of Ticks instead.

static JsonNumber Create(DateTime value)

Returns a JsonNumber corresponding to the number of seconds elapsed since UNIX Epoch

  • value — DateTime to convert

Returns: JSON value that will be serialized as a decimal value.

By convention, MinValue is equivalent to 0, and MaxValue is equivalent to NaN.

This method can introduce rounding errors, so value may not round-trip in all cases.

If an exact representation is required, please serialize the date as a string instead.

static JsonNumber Create(DateTimeOffset value)

Returns a JsonNumber corresponding to the number of seconds elapsed since UNIX Epoch

  • value — DateTimeOffset to convert

Returns: JSON value that will be serialized as a decimal value.

By convention, MinValue is equivalent to 0, and MaxValue is equivalent to NaN.

This method can introduce rounding errors, so value may not round-trip in all cases.

If an exact representation is required, please serialize the date as a string instead.

static JsonNumber Create(DateOnly value)

Returns a JsonNumber corresponding to the number of days elapsed since the UNIX Epoch

static JsonNumber Create(TimeOnly value)

Returns a JsonNumber corresponding to the number of seconds elapsed since midnight

  • value — Time to convert

Returns: JSON value that will be serialized as a decimal value.

This method can introduce rounding errors, so value may not round-trip in all cases.

If an exact representation is required, please serialize the date as a string instead.

static JsonNumber Create(Instant value)

Returns a JsonNumber corresponding to the number of seconds elapsed since UNIX Epoch

  • value — Instant to convert

Returns: JSON value that will be serialized as a decimal value.

This method can introduce rounding errors, so value may not round-trip in all cases.

If an exact representation is required, please serialize the date as a string instead.

static JsonNumber Create(Duration value)

Returns a JsonNumber corresponding to the number of seconds elapsed

Divide

JsonNumber Divide(JsonNumber number)

Divides this number by another number

Equals

bool Equals(object value)

bool Equals(JsonValue value)

Tests if these two JSON values are considered equal, using the relaxed JSON comparison semantics

Two values are considered "equal" if they would produce the same result when serialized using a canonical representation.

Numbers are equal if they represent the "same" number (ie: 1 and 1.0 are equal)

Numbers and strings can be equal, if the later can be parsed into a number equal to the former (ie: 123 and "123" are equal)

Arrays are equal if they have the same length and all their elements are equals pairwise

Objects are equal if they have the same key/value pairs, irrespective of their order.

A Missing field is not considered equal to an explicit Null field, and vice versa

If you require strict equality (ie: "123" and 123 are different), consider calling StrictEquals instead.

bool Equals(JsonNumber value)

bool Equals(JsonString value)

bool Equals(JsonBoolean value)

bool Equals(JsonDateTime value)

bool Equals(short value)

bool Equals(ushort value)

bool Equals(int value)

bool Equals(uint value)

bool Equals(long value)

bool Equals(ulong value)

bool Equals(Int128 value)

bool Equals(UInt128 value)

bool Equals(Uuid48 value)

bool Equals(float value)

bool Equals(double value)

bool Equals(Half value)

bool Equals(decimal value)

bool Equals(TimeSpan value)

GetHashCode

int GetHashCode()

Returns a hash code that can be used to quickly identify a JSON value.

The hash code is guaranteed to remain unchanged during the lifetime of the object.

Caution: there is NO guarantee that two equivalent Objects or Arrays will have the same hash code! This means that it is NOT safe to use a JSON object or array has the key of a Dictionary or other collection that uses hash codes to quickly compare two instances.

IsBetween

bool IsBetween(long minInclusive, long maxInclusive)

Tests if the number is between the specified bounds (both included)

  • minInclusive — Minimum value (included)
  • maxInclusive — Maximum value (included)

Returns: true if minInclusive <= x <= maxInclusive

bool IsBetween(ulong minInclusive, ulong maxInclusive)

Tests if the number is between the specified bounds (both included)

  • minInclusive — Minimum value (included)
  • maxInclusive — Maximum value (included)

Returns: true if minInclusive <= x <= maxInclusive

bool IsBetween(double minInclusive, double maxInclusive)

Tests if the number is between the specified bounds (both included)

  • minInclusive — Minimum value (included)
  • maxInclusive — Maximum value (included)

Returns: true if minInclusive <= x <= maxInclusive

IsEvenInteger

static bool IsEvenInteger(JsonNumber value)

IsFinite

static bool IsFinite(JsonNumber value)

IsInfinity

static bool IsInfinity(JsonNumber value)

IsInteger

static bool IsInteger(JsonNumber value)

IsNaN

static bool IsNaN(JsonNumber value)

IsNegativeInfinity

static bool IsNegativeInfinity(JsonNumber value)

IsNormal

static bool IsNormal(JsonNumber value)

IsOddInteger

static bool IsOddInteger(JsonNumber value)

IsPositive

static bool IsPositive(JsonNumber value)

IsPositiveInfinity

static bool IsPositiveInfinity(JsonNumber value)

IsRealNumber

static bool IsRealNumber(JsonNumber value)

IsSubnormal

static bool IsSubnormal(JsonNumber value)

IsZero

static bool IsZero(JsonNumber value)

JsonSerialize

void JsonSerialize(CrystalJsonWriter writer)

Serializes this instance as JSON

  • writer — Writer that will output the content of this instance

MaxMagnitude

static JsonNumber MaxMagnitude(JsonNumber x, JsonNumber y)

MaxMagnitudeNumber

static JsonNumber MaxMagnitudeNumber(JsonNumber x, JsonNumber y)

MinMagnitude

static JsonNumber MinMagnitude(JsonNumber x, JsonNumber y)

MinMagnitudeNumber

static JsonNumber MinMagnitudeNumber(JsonNumber x, JsonNumber y)

Minus

JsonNumber Minus(JsonNumber number)

Subtracts a number from this number

Multiply

JsonNumber Multiply(JsonNumber number)

Multiply this number with another number

Parse

static JsonNumber Parse(string s, IFormatProvider provider)

static JsonNumber Parse(ReadOnlySpan<char> s, IFormatProvider provider)

Parses a JSON text literal, and returns the corresponding JSON value.

  • provider — This parameter is ignored.

Returns: Corresponding JSON value. If jsonText is empty, will return Missing

It is better to call overloads of this method that accept a argument.

Plus

JsonNumber Plus(JsonNumber number)

Adds this number with another number

Return

static JsonValue Return(string value)

Returns the equivalent JsonNumber

static JsonValue Return(byte value)

Returns the equivalent JsonNumber

static JsonValue Return(byte? value)

Returns the equivalent JsonNumber

static JsonValue Return(sbyte value)

Returns the equivalent JsonNumber

static JsonValue Return(sbyte? value)

Returns the equivalent JsonNumber

static JsonValue Return(short value)

Returns the equivalent JsonNumber

static JsonValue Return(short? value)

Returns the equivalent JsonNumber

static JsonValue Return(ushort value)

Returns the equivalent JsonNumber

static JsonValue Return(ushort? value)

Returns the equivalent JsonNumber

static JsonValue Return(int value)

Returns the equivalent JsonNumber

  • value — Integer value

Returns: JSON value that will be serialized as an integer.

For small values a cached singleton is returned. For others values, a new instance will be allocated.

static JsonValue Return(int? value)

Returns the equivalent JsonNumber

  • value — Integer value, that can be null.

Returns: JSON value that will be serialized as an integer, or Null.

For small values a cached singleton is returned. For others values, a new instance will be allocated.

static JsonValue Return(uint value)

Returns the equivalent JsonNumber

  • value — Integer value

Returns: JSON value that will be serialized as an integer.

For small values a cached singleton is returned. For others values, a new instance will be allocated.

static JsonValue Return(uint? value)

Returns the equivalent JsonNumber

  • value — Integer value, that can be null.

Returns: JSON value that will be serialized as an integer, or Null.

For small values a cached singleton is returned. For others values, a new instance will be allocated.

static JsonValue Return(long value)

Returns the equivalent JsonNumber

  • value — Integer value

Returns: JSON value that will be serialized as an integer.

For small values (between -128 and 255) a cached singleton is returned. For others values, a new instance will be allocated.

static JsonValue Return(long? value)

Returns the equivalent JsonNumber

static JsonValue Return(ulong value)

Returns the equivalent JsonNumber

  • value — Integer value

Returns: JSON value that will be serialized as an integer.

For small values (between 0 and 255) a cached singleton is returned. For others values, a new instance will be allocated.

static JsonValue Return(ulong? value)

Returns the equivalent JsonNumber

static JsonValue Return(double value)

Returns the equivalent JsonNumber

  • value — Decimal value

Returns: JSON value that will be serialized as a decimal value.

For , and NaN a cached singleton is returned. For others values, a new instance will be allocated.

static JsonValue Return(double? value)

Returns the equivalent JsonNumber

static JsonValue Return(float value)

Returns the equivalent JsonNumber

  • value — Decimal value

Returns: JSON value that will be serialized as a decimal value.

For , and NaN a cached singleton is returned. For others values, a new instance will be allocated.

static JsonValue Return(float? value)

Returns the equivalent JsonNumber

static JsonValue Return(Half value)

Returns the equivalent JsonNumber

  • value — Decimal value

Returns: JSON value that will be serialized as a decimal value.

For , and NaN a cached singleton is returned. For others values, a new instance will be allocated.

static JsonValue Return(Half? value)

Returns the equivalent JsonNumber

static JsonValue Return(decimal value)

Returns the equivalent JsonNumber

static JsonValue Return(decimal? value)

Returns the equivalent JsonNumber

static JsonValue Return(Int128 value)

Returns the equivalent JsonNumber

static JsonValue Return(Int128? value)

Returns the equivalent JsonNumber

static JsonValue Return(UInt128 value)

Returns the equivalent JsonNumber

static JsonValue Return(UInt128? value)

Returns the equivalent JsonNumber

static JsonValue Return(Uuid48 value)

Returns the equivalent JsonNumber

static JsonValue Return(Uuid48? value)

Returns the equivalent JsonNumber

static JsonValue Return(TimeSpan value)

Returns a JsonNumber corresponding to the number of seconds in the interval

  • value — Interval (in seconds)

Returns: JSON value that will be serialized as a decimal value.

Since TotalSeconds can introduce rounding errors, this value may not round-trip in all cases.

If an exact representation is required, please serialize the number of Ticks instead.

static JsonValue Return(TimeSpan? value)

Returns a JsonNumber corresponding to the number of seconds in the interval

  • value — Interval to convert, or null

Returns: JSON value that will be serialized as a decimal value, or Null.

This method can introduce rounding errors, so value may not round-trip in all cases.

If an exact representation is required, please serialize the number of Ticks instead.

static JsonValue Return(DateTime value)

Returns a JsonNumber corresponding to the number of seconds elapsed since UNIX Epoch

  • value — DateTime to convert

Returns: JSON value that will be serialized as a decimal value.

By convention, MinValue is equivalent to 0, and MaxValue is equivalent to NaN.

This method can introduce rounding errors, so value may not round-trip in all cases.

If an exact representation is required, please serialize the date as a string instead.

static JsonValue Return(DateTime? value)

Returns a JsonNumber corresponding to the number of seconds elapsed since UNIX Epoch

  • value — DateTime to convert, or null

Returns: JSON value that will be serialized as a decimal value, or Null.

By convention, MinValue is equivalent to 0, and MaxValue is equivalent to NaN.

This method can introduce rounding errors, so value may not round-trip in all cases.

If an exact representation is required, please serialize the date as a string instead.

static JsonValue Return(DateTimeOffset value)

Returns a JsonNumber corresponding to the number of seconds elapsed since UNIX Epoch

  • value — DateTimeOffset to convert

Returns: JSON value that will be serialized as a decimal value.

By convention, MinValue is equivalent to 0, and MaxValue is equivalent to NaN.

This method can introduce rounding errors, so value may not round-trip in all cases.

If an exact representation is required, please serialize the date as a string instead.

static JsonValue Return(DateTimeOffset? value)

Returns a JsonNumber corresponding to the number of seconds elapsed since UNIX Epoch

  • value — DateTimeOffset to convert, or null

Returns: JSON value that will be serialized as a decimal value, or Null.

By convention, MinValue is equivalent to 0, and MaxValue is equivalent to NaN.

This method can introduce rounding errors, so value may not round-trip in all cases.

If an exact representation is required, please serialize the date as a string instead.

static JsonValue Return(DateOnly value)

Returns a JsonNumber corresponding to the number of days elapsed since the UNIX Epoch

static JsonValue Return(DateOnly? value)

Returns a JsonNumber corresponding to the number of days elapsed since the UNIX Epoch

static JsonValue Return(TimeOnly value)

Returns a JsonNumber corresponding to the number of seconds elapsed since midnight

  • value — Time to convert

Returns: JSON value that will be serialized as a decimal value.

This method can introduce rounding errors, so value may not round-trip in all cases.

If an exact representation is required, please serialize the date as a string instead.

static JsonValue Return(TimeOnly? value)

Returns a JsonNumber corresponding to the number of seconds elapsed since midnight

  • value — Time to convert, or null

Returns: JSON value that will be serialized as a decimal value, or Null.

This method can introduce rounding errors, so value may not round-trip in all cases.

If an exact representation is required, please serialize the date as a string instead.

static JsonValue Return(Instant value)

Returns a JsonNumber corresponding to the number of seconds elapsed since UNIX Epoch

  • value — Instant to convert

Returns: JSON value that will be serialized as a decimal value.

This method can introduce rounding errors, so value may not round-trip in all cases.

If an exact representation is required, please serialize the date as a string instead.

static JsonValue Return(Instant? value)

Returns a JsonNumber corresponding to the number of seconds elapsed since UNIX Epoch

static JsonValue Return(Duration value)

Returns a JsonNumber corresponding to the number of seconds elapsed

static JsonValue Return(Duration? value)

Returns a JsonNumber corresponding to the number of seconds elapsed

StrictEquals

bool StrictEquals(JsonValue other)

Tests if these two JSON values are considered equal, using the strict JSON comparison semantics

For two values to be considered "equal", they must be of the same type (string, number, array, ...) AND have the same result when serialized using a canonical representation.

Arrays are equals if they have the same length and all their elements are also strictly equal.

Objects are equal if they have the same keys, irrespective of their order, and each value is strictly equal.

A Missing field is not considered equal to an explicit Null field, and vice versa

bool StrictEquals(JsonNumber other)

ToBoolean

bool ToBoolean(bool _ = false)

Returns the equivalent Boolean, if there exists a valid conversion

ToByte

byte ToByte(byte _ = 0)

Returns the equivalent Byte, if there exists a valid conversion

ToChar

char ToChar(char _ = '�')

Returns the equivalent Char, if there exists a valid conversion

ToDateOnly

DateOnly ToDateOnly(DateOnly _ = null)

Converts this JsonNumber, interpreted as the number of days since Unix Epoch, into a DateOnly

Returns: DateOnly equal to epoch(1970-1-1Z) + days(value)

ToDateTime

DateTime ToDateTime(DateTime _ = null)

Converts this JsonNumber, interpreted as the number of seconds since Unix Epoch, into a DateTime (UTC)

Returns: DateTime (in UTC) equal to epoch(1970-1-1Z) + seconds(value)

ToDateTimeOffset

DateTimeOffset ToDateTimeOffset(DateTimeOffset _ = null)

Converts this JsonNumber, interpreted as the number of seconds since Unix Epoch, into a DateTimeOffset

Returns: DateTimeOffset (UTC) equal to epoch(1970-1-1Z) + seconds(value)

Since the original TimeZone information is lost, the result with have a time offset of .

ToDecimal

decimal ToDecimal(decimal _ = 0)

Returns the equivalent Decimal, if there exists a valid conversion

ToDouble

double ToDouble(double _ = 0)

Returns the equivalent Double, if there exists a valid conversion

ToDuration

Duration ToDuration(Duration _ = null)

Returns the equivalent Duration, if there exists a valid conversion

ToEnum

TEnum ToEnum<TEnum>(TEnum _ = null)

Returns the equivalent Enum, if there exists a valid conversion

ToHalf

Half ToHalf(Half _ = null)

Returns the equivalent Half, if there exists a valid conversion

ToInstant

Instant ToInstant(Instant _ = null)

Returns the equivalent Instant, if there exists a valid conversion

ToInt128

Int128 ToInt128(Int128 _ = null)

Returns the equivalent Int128, if there exists a valid conversion

ToInt16

short ToInt16(short _ = 0)

Returns the equivalent Int16, if there exists a valid conversion

ToInt32

int ToInt32(int _ = 0)

Returns the equivalent Int32, if there exists a valid conversion

ToInt64

long ToInt64(long _ = 0)

Returns the equivalent Int64, if there exists a valid conversion

ToJsonText

string ToJsonText(CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null)

Serializes this JSON value into a JSON string literal

  • settings — Settings used to change the serialized JSON output (optional)
  • resolver — Optional custom resolver.

Returns: JSON text literal that can be written to disk, returned as the body of an HTTP request, or

var jsonText = new JsonObject() { ["hello"] = "world" }.ToJsonText(); // == "{ "hello": "world" }"

ToObject

object ToObject()

Converts this number into a type that closely matches the value (integer or decimal)

Returns: Return either an int/long for integers, or a double/decimal for floating point numbers

For integers: If the value is between int.MinValue and int.MaxValue, it will be cast to ; otherwise, it will be cast to .

ToSByte

sbyte ToSByte(sbyte _ = 0)

Returns the equivalent SByte, if there exists a valid conversion

ToSingle

float ToSingle(float _ = 0)

Returns the equivalent Single, if there exists a valid conversion

ToString

string ToString()

Converts this JSON value into a printable string

Please note that, due to convention in .NET, this will return the empty string for null values, since ToString must not return a null reference! Please call ToStringOrDefault if you need null references for null or missing JSON values.

See ToString if you need to specify a different format than the default

ToTimeOnly

TimeOnly ToTimeOnly(TimeOnly _ = null)

Converts this JsonNumber, interpreted as the number of seconds since midnight, into a DateOnly

Returns: TimeOnly (UTC) equal to MinValue + seconds(value)

ToTimeSpan

TimeSpan ToTimeSpan(TimeSpan _ = null)

Returns the equivalent TimeSpan, if there exists a valid conversion

ToUInt128

UInt128 ToUInt128(UInt128 _ = null)

Returns the equivalent UInt128, if there exists a valid conversion

ToUInt16

ushort ToUInt16(ushort _ = 0)

Returns the equivalent UInt16, if there exists a valid conversion

ToUInt32

uint ToUInt32(uint _ = 0)

Returns the equivalent UInt32, if there exists a valid conversion

ToUInt64

ulong ToUInt64(ulong _ = 0)

Returns the equivalent UInt64, if there exists a valid conversion

ToUuid48

Uuid48 ToUuid48(Uuid48 _ = null)

Returns the equivalent Uuid48, if there exists a valid conversion

TryConvertFrom

static bool TryConvertFrom<TOther>(TOther value, out JsonNumber result)

TryConvertFromChecked

static bool TryConvertFromChecked<TOther>(TOther value, out JsonNumber result)

TryConvertFromSaturating

static bool TryConvertFromSaturating<TOther>(TOther value, out JsonNumber result)

TryConvertFromTruncating

static bool TryConvertFromTruncating<TOther>(TOther value, out JsonNumber result)

TryConvertToChecked

static bool TryConvertToChecked<TOther>(JsonNumber value, out TOther result)

TryConvertToSaturating

static bool TryConvertToSaturating<TOther>(JsonNumber value, out TOther result)

TryConvertToTruncating

static bool TryConvertToTruncating<TOther>(JsonNumber value, out TOther result)

TryFormat

bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = null, IFormatProvider provider = null)

bool TryFormat(Span<byte> destination, out int bytesWritten, ReadOnlySpan<char> format = null, IFormatProvider provider = null)

TryParse

static bool TryParse(string s, IFormatProvider provider, out JsonNumber result)

static bool TryParse(ReadOnlySpan<char> s, IFormatProvider provider, out JsonNumber result)

ValueEquals

bool ValueEquals<TValue>(TValue value, IEqualityComparer<TValue> comparer = null)

Tests if the current instance is equal to the specified value, using the strict JSON comparison semantics

  • value — Value to test with the current instance
  • comparer — Custom equality comparer if specified; otherwise, uses the default comparer for this type

Returns: true if both arguments are considered equal; otherwise, false

This method tries to perform an optimized comparison, and should perform less memory allocations than calling

WriteTo

void WriteTo(ref SliceWriter writer)

Serializes the current instance to the specified output buffer

Fields

DecimalOne

static readonly JsonNumber DecimalOne

1.0 (double)

DecimalZero

static readonly JsonNumber DecimalZero

0.0 (double)

NaN

static readonly JsonNumber NaN

NaN (double)

NegativeInfinity

static readonly JsonNumber NegativeInfinity

-∞ (double)

PI

static readonly JsonNumber PI

π ~= 3.1415926535897931 (double)

PositiveInfinity

static readonly JsonNumber PositiveInfinity

+∞ (double)

Tau

static readonly JsonNumber Tau

τ ~= 6.283185307179586 (double)