JsonValueAsNumber Property

Gets the numeric value of this JsonValue instance if it has Number Type; or , if its Type is not Number. The returned value is a double to be conform with JSON Number type. To retrieve the actual stored raw value use the AsLiteral property. To retrieve the value as .NET numeric types use the methods in the JsonValueExtensions class.


Namespace: KGySoft.Json
Assembly: KGySoft.Json (in KGySoft.Json.dll) Version: 3.0.0
public double? AsNumber { get; }

Property Value



When getting this property the stored underlying string is converted to a double so it has the same behavior as a JavaScript Number.

If this JsonValue was created from a C# long or decimal value (see the ToJson overloads), then this property may return a different value due to loss of precision. This is how JavaScript also behaves. To get the value as specific .NET numeric types use the extension methods in the JsonValueExtensions class.

To retrieve the stored actual raw value without any conversion you can use the AsLiteral property.

This property may return if this instance was created by the CreateNumberUnchecked method and contains an invalid number.

This property can also return when a NaN or Infinity/-Infinity was parsed, which are not valid in JSON. But even such values can be retrieved as a double by the AsDouble extension method.

See Also