IJsonValue

Description

interface Tinman.Core.Formatting.IJsonValue

Derived from

ICodeOutput
IEquatable<IJsonValue>

Extended by

JsonValue sealed

Represents read-only access to a parsed JSON value.

A JSON value always has one of the following data types:

The JSON value may be accessed via the following getter methods, which will perform value conversions, if possible:

Use ToFile and ToString to generate parsable JSON code. To parse JSON code, use JsonValue.From1 and JsonValue.FromFile.

See also

JsonValue

Public / Methods

Copy


public method Copy → ()

returns → JsonValue

The mutable copy.

Creates a mutable copy of this JSON value.

Modifying the returned JsonValue will not affect this JSON value.

Get​Boolean


[Pure]
public method GetBoolean → (1)

defaultValue opt : bool = false

The default value to return if this JSON value cannot be interpreted as a boolean value.

returns → bool

The boolean value.

Returns this JSON value as a boolean value.

The following values are returned by this method, depending on the JSON value type:

  • array : defaultValue opt

  • boolean : value

  • integer : false if value is 0, otherwise true

  • null : defaultValue opt

  • number : false if value is 0, otherwise true

  • object : defaultValue opt

  • string : true if value is 'true', otherwise false

Get​Element


[Pure]
public method GetElement → (1)

index in : int32

The array element index.

returns → IJsonValue

The array element value. Will be JsonValue.Null if this JSON value does not contain the requested value.

Returns the index in-th array element of this JSON value.

The following values are returned by this method, depending on the JSON value type:

Get​Float32


[Pure]
public method GetFloat32 → (1)

defaultValue opt : float32 = 0

The default value to return if this JSON value cannot be interpreted as a floating point value.

returns → float32

The floating point value.

Returns this JSON value as a 32-bit floating point value.

The following values are returned by this method, depending on the JSON value type:

  • array : defaultValue opt

  • boolean : 1 for true, 0 for false

  • integer : value, cast to integer

  • null : defaultValue opt

  • number : value

  • object : defaultValue opt

  • string : value parsed with Parse.Number, on failure defaultValue opt

Get​Float64


[Pure]
public method GetFloat64 → (1)

defaultValue opt : float64 = 0

The default value to return if this JSON value cannot be interpreted as a floating point value.

returns → float64

The floating point value.

Returns this JSON value as a 64-bit floating point value.

The following values are returned by this method, depending on the JSON value type:

  • array : defaultValue opt

  • boolean : 1 for true, 0 for false

  • integer : value, cast to integer

  • null : defaultValue opt

  • number : value

  • object : defaultValue opt

  • string : value parsed with Parse.Number, on failure defaultValue opt

Get​Int32


[Pure]
public method GetInt32 → (1)

defaultValue opt : int32 = 0

The default value to return if this JSON value cannot be interpreted as an integer value.

returns → int32

The integer value.

Returns this JSON value as a 32-bit integer value.

The following values are returned by this method, depending on the JSON value type:

  • array : defaultValue opt

  • boolean : 1 for true, 0 for false

  • integer : value

  • null : defaultValue opt

  • number : value, cast to number

  • object : defaultValue opt

  • string : value parsed with Parse.Integer, on failure parsed with Parse.Number and cast to integer, on failure defaultValue opt

Get​Int64


[Pure]
public method GetInt64 → (1)

defaultValue opt : int64 = 0

The default value to return if this JSON value cannot be interpreted as an integer value.

returns → int64

The integer value.

Returns this JSON value as a 64-bit integer value.

The following values are returned by this method, depending on the JSON value type:

  • array : defaultValue opt

  • boolean : 1 for true, 0 for false

  • integer : value

  • null : defaultValue opt

  • number : value, cast to number

  • object : defaultValue opt

  • string : value parsed with Parse.Integer, on failure parsed with Parse.Number and cast to integer, on failure defaultValue opt

Get​Member

2 overloads


[Pure]
public method GetMember1 → (1)

index in : int32

The object member index.

returns → IJsonValue

The object member value. Will be JsonValue.Null if this JSON value does not contain the requested value.

Returns the value of the given object member.


[Pure]
public method GetMember2 → (1)

name in : string

The object member name.

returns → IJsonValue

The object member value. Will be JsonValue.Null if this JSON value does not contain the requested value.

Returns the value of the given object member.

Get​Member​Comment


[Pure]
public method GetMemberComment → (1)

index in : int32

The object member index.

returns → string

The object member comment. Will be null if this JSON value does not contain the requested value.

Returns the comment of the given object member.

Comments are not a part of the official JSON specification and should not be used to represent data. When outputting JSON code in plain ASCII, all non-ASCII characters in comments will be replaced with '?'.

Get​Member​Index


[Pure]
public method GetMemberIndex → (1)

name in : string

The object member name.

returns → int32

The object member index of -1 if no such member exists.

Returns the index of the given object member.

Get​Member​Name


[Pure]
public method GetMemberName → (1)

index in : int32

The object member index.

returns → string

The object member name. Will be null if this JSON value does not contain the requested value.

Returns the name of the given object member.

Get​Member​Null


[Pure]
public method GetMemberNull → (1)

name in : string

The object member name.

returns → IJsonValue

The object member value. Will be null if this JSON value does not contain the requested value.

Returns the value of the given object member.

Get​String


[Pure]
public method GetString → (1)

defaultValue opt : string = null

The default value to return if this JSON value cannot be interpreted as a string value.

returns → string

The string value.

Returns this JSON value as a string.

Has​Member


[Pure]
public method HasMember → (1)

name in : string

The object member name.

returns → bool

true if the object member exists,
false if it does not exist.

Returns whether the given object member exists.

Is​Array


[Pure]
public method IsArray → (1)

length opt : int32 = -1

The expected array length. If less than zero, the array length is not checked.

returns → bool

true if this JSON value is of type array and has the expected length, false if not.

Is this JSON value of type array?

To​File


[Pure]
public method ToFile → (3)

file in : Path

[not-null]
The file path.

minify opt : bool = false

true to output minified code, false to output human-readable code.

ascii opt : bool = false

true to use only ASCII characters, escaping Unicode characters if present
false to use Unicode characters in the string representation, without escaping.

Writes this JSON value to the given file.

IOException

If an I/O error has occurred.

To​String


[Pure]
public method ToString → (2)

minify in : bool

true to output minified code, false to output human-readable code.

ascii opt : bool = false

true to use only ASCII characters, escaping Unicode characters if present
false to use Unicode characters in the string representation, without escaping.

returns → string

The parsable string representation.

Returns the parsable string representation of this JSON value.

See also

JsonValue.From1

Public / Attributes

Count


public attribute Count → (get)

value : int32

[>=0]
The number of aggregated values.

Returns the number of array elements or object members in this JSON value.

Elements


public attribute Elements → (get)

value : IVectorConst<IJsonValue>

[not-null]
The list of array elements. Will be empty if IsArray returns false.

Returns the array elements of this JSON value.

This collection should only be used if Count and GetElement and not suitable.

Is​Boolean


public attribute IsBoolean → (get)

value : bool

true if this JSON value is of type boolean, false if not.

Is this JSON value of type boolean?

Is​Integer


public attribute IsInteger → (get)

value : bool

true if this JSON value is of type integer, false if not.

Is this JSON value of type integer?

Is​Null


public attribute IsNull → (get)

value : bool

true if this JSON value is null, false if not.

Is this JSON value null?

Is​Number


public attribute IsNumber → (get)

value : bool

true if this JSON value is of type number, false if not.

Is this JSON value of type number?

Is​Object


public attribute IsObject → (get)

value : bool

true if this JSON value is of type object, false if not.

Is this JSON value of type object?

Is​String


public attribute IsString → (get)

value : bool

true if this JSON value is of type string, false if not.

Is this JSON value of type string?