JsonValue

Description

sealed class Tinman.Core.Formatting.JsonValue

Derived from

IJsonValue
ISerializable

Represents a mutable JSON value.

A formatted JSON value must be written in the following Grammar:

json     := value ;

array    := '[' (value .. ',')? ']' ;
member   := string ':' value ;
object   := '{' (comment* member .. ',')? '}' ;
value    := 'false' | 'null' | 'true' | object | array | number | string ;

string   := '"' (no-chars+ | escape)* '"' ;

escape   := '\\' (["/\\bfnrt] | 'u' hexdigit[4]) ;

hexdigit := 'a'..'f' | 'A'..'F' | digit ;
number   := '-'? ('0' | '1'..'9' digit*) ('.' digit+)? (('e' | 'E') ('+' | '-')? digit+)? ;

comment  := '//' ' '? ]\n\r[* '\r'? '\n' ;
digit    := '0'..'9' ;
no-chars := ]\0\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0B\x0C\r\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"\\[ ;

The following methods may be used to set the value, changing the value type:

The following methods may be used to build array values, changing the value type to array:

The following methods may be used to build object values, changing the value type to object:

The IJsonValue interface may be used to pass around read-only references to JsonValue objects.

Public / Constants

Empty


[ShutdownSurvive]
public static readonly attribute Empty → (IJsonValue)

The JSON value for the empty string.

This is not a singleton value, there may be other JsonValue objects that are equal to this one.

False


[ShutdownSurvive]
public static readonly attribute False → (IJsonValue)

The false JSON value.

This is not a singleton value, there may be other JsonValue objects that are equal to this one.

Null


[ShutdownSurvive]
public static readonly attribute Null → (IJsonValue)

The null JSON value.

This is not a singleton value, there may be other JsonValue objects that are equal to this one.

True


[ShutdownSurvive]
public static readonly attribute True → (IJsonValue)

The true JSON value.

This is not a singleton value, there may be other JsonValue objects that are equal to this one.

Public / Constructors

From

2 overloads


public static method From1 → (1)

text in : string

[not-null]
The JSON code.

returns → JsonValue

The JsonValue object.

Creates a JsonValue from the given text.

ValidatingException

If the given source code text in is malformed.


public static method From2 → (1)

value in : IJsonValue

The source value.

returns → JsonValue

The JsonValue object. Will be the same object as value in if the latter is an instance of JsonValue.

Creates a new instance of JsonValue.

From​File


public static method FromFile → (1)

file in : Path

[not-null]
The file path.

returns → JsonValue

The JsonValue object or Null if the file does not exist.

Creates a JsonValue from the given file.

The given file in is expected to be in UTF-8 encoding, without BOM.

IOException

If an I/O error has occurred.

ValidatingException

If the given file in contains malformed source code.

Json​Value


public constructor JsonValue → ()

Creates a new instance of JsonValue.

Public / Methods

Element

6 overloads


public method Element1 → (1)

value in : bool

The element value to append.

returns → JsonValue

this

Appends an array element value to this JSON value.


public method Element2 → (1)

value in : int32

The element value to append.

returns → JsonValue

this

Appends an array element value to this JSON value.


public method Element3 → (1)

value in : int64

The element value to append.

returns → JsonValue

this

Appends an array element value to this JSON value.


public method Element4 → (1)

value in : float64

The element value to append.

returns → JsonValue

this

Appends an array element value to this JSON value.


public method Element5 → (1)

value in : string

The element value to append.

returns → JsonValue

this

Appends an array element value to this JSON value.


public method Element6 → (1)

value in : IJsonValue

The element value to append (by reference).

returns → JsonValue

this

Appends an array element value to this JSON value.

Element​Add


public method ElementAdd → ()

returns → JsonValue

The appended array element value.

Appends an array element value to this JSON value.

Element​Prepare


public method ElementPrepare → (1)

capacity opt : int32 = 0

[>=0]
The capacity to use for preparing the element list.

returns → JsonValue

this

Turns this JSON value into an array with elements.

This method may be used when building a JSON array from a known number of elements, in order to make sure that the underlying collection has the optimal capacity.

See also

JsonValue.Trim

Element​Remove


public method ElementRemove → (1)

index in : int32

The array element index.

returns → JsonValue

this

Removes the index in-th array element value from this JSON value.

Member

6 overloads


public method Member1 → (3)

name in : string

[not-empty]
The member name.

value in : bool

The member value.

comment opt : string = null

Optional comment string.

returns → JsonValue

this

Sets an object member of this JSON value.


public method Member2 → (3)

name in : string

[not-empty]
The member name.

value in : int32

The member value.

comment opt : string = null

Optional comment string.

returns → JsonValue

this

Sets an object member of this JSON value.


public method Member3 → (3)

name in : string

[not-empty]
The member name.

value in : int64

The member value.

comment opt : string = null

Optional comment string.

returns → JsonValue

this

Sets an object member of this JSON value.


public method Member4 → (3)

name in : string

[not-empty]
The member name.

value in : float64

The member value.

comment opt : string = null

Optional comment string.

returns → JsonValue

this

Sets an object member of this JSON value.


public method Member5 → (3)

name in : string

[not-empty]
The member name.

value in : string

The member value.

comment opt : string = null

Optional comment string.

returns → JsonValue

this

Sets an object member of this JSON value.


public method Member6 → (3)

name in : string

[not-empty]
The member name.

value in : IJsonValue

The member value (by reference).

comment opt : string = null

Optional comment string.

returns → JsonValue

this

Sets an object member of this JSON value.

Member​Add


public method MemberAdd → (2)

name in : string

[not-empty]
The member name.

comment opt : string = null

Optional comment string.

returns → JsonValue

The added member value.

Adds an object member to this JSON value.

Member​Prepare


public method MemberPrepare → (1)

capacity opt : int32 = 0

[>=0]
The capacity to use for preparing the member list.

returns → JsonValue

this

Turns this JSON value into an object with members.

This method may be used when building a JSON object from a known number of members, in order to make sure that the underlying collection has the optimal capacity.

See also

JsonValue.Trim

Member​Remove


public method MemberRemove → (1)

name in : string

[not-empty]
The member name.

returns → JsonValue

this

Removes an object member from this JSON value.

Set

6 overloads


public method Set1 → ()

returns → JsonValue

this

Sets the value of this JSON value to null.


public method Set2 → (1)

value in : bool

The new value.

returns → JsonValue

this

Sets the value of this JSON value.


public method Set3 → (1)

value in : int32

The new value.

returns → JsonValue

this

Sets the value of this JSON value.


public method Set4 → (1)

value in : int64

The new value.

returns → JsonValue

this

Sets the value of this JSON value.


public method Set5 → (1)

value in : float64

The new value.

returns → JsonValue

this

Sets the value of this JSON value.

The JSON specification does not include infinity or not-a-number. These will be replaced as follows:


public method Set6 → (1)

value in : string

The new value.

returns → JsonValue

this

Sets the value of this JSON value.

Trim


public method Trim → ()

returns → JsonValue

this

Trims the capacity of the member list resp. element array to the actual number of items.

This method can be used after building a JsonValue and before passing it around as a read-only IJsonValue, in order to make sure that no memory is wasted in the underlying collections.

Serialization

Serial​Id


public static readonly attribute SerialId → (ISerialTypeInfo)

Serialization information about this type.