Interface IJSON

The immutable JSON data value.

Inherited Members
IBytes.Length
IBytes.AsInputStream()
IBytes.ToByteArray()
IBytes.CopyTo(Stream)
Namespace: PushTechnology.ClientInterface.Data.JSON
Assembly: Diffusion.Client.dll
Syntax
public interface IJSON : IBytes
Remarks

JSON is "JavaScript Object Notation", a lightweight data-interchange format. See www.json.org.

To create an instance from a JSON string, obtain a IJSONDataType implementation from Diffusion.DataTypes.JSON and call FromJSONString(String).

The ToJSONString() method can be used to retrieve this value as a JSON string. Applications can use a JSON library to create and interpret the JSON data represented as a string.

CBOR representation

Internally the value is stored and transmitted not as a JSON string, but in CBOR format to reduce memory and network overhead. CBOR (Concise Binary Object Representation) is a standardized format for binary representation of structured data defined by RFC 7049. See www.cbor.io.

Rather than working with JSON strings it is possible, and usually preferable, for applications to work directly with the underlying CBOR-format binary representation. This avoids creating intermediate JSON strings, and allows access to CBOR features such as the byte string data type.

Each JSON value is represented as a single CBOR data item. CBOR supports composite data types just like JSON, so this data item can be an array or a map of other data items. The JSON null value is represented by the CBOR Null value.

A particular advantage of working directly with the CBOR-format data is that binary data can be written to the value as a data item using the CBOR byte string type. The data item will be stored as part of the JSON value in binary form and transmitted without further conversion.

Working with CBOR data

To create an instance from a CBOR-format byte array, call ReadValue(Byte[]). The byte array must contain a single CBOR data item, otherwise, an System.IO.InvalidDataException will be thrown when the data is first parsed. To convert an instance to CBOR format, use AsInputStream() or IJSONDataType.WriteValue(IJSON,OutputStream).

To read or write CBOR we recommend using our own basic CBORReader and CBORWriter classes, or some other library of your choice.

CBOR limitations

The mapping from a JSON string to and from CBOR-format binary data is mostly straightforward, but there are a few limitations. In particular:

  • Non-string keys are not supported.
  • Precision may be lost converting numbers from JSON to CBOR.

Since 5.8

Methods

Apply(IBinaryDelta)

Applies a binary delta to this JSON value to create a new value.

Declaration
IJSON Apply(IBinaryDelta delta)
Parameters
Type Name Description
IBinaryDelta delta

The binary delta to apply to this JSON value.

Returns
Type Description
IJSON

The new JSON value.

Remarks

Convenient equivalent to Diffusion.DataTypes.JSON.BinaryDeltaType.Apply(this, delta) .

BinaryDiff(IJSON)

Compares this JSON value with an earlier version to create a binary delta.

Declaration
IBinaryDelta BinaryDiff(IJSON original)
Parameters
Type Name Description
IJSON original

The original JSON value.

Returns
Type Description
IBinaryDelta

The delta representing the difference between original and this JSON.

Remarks

Convenient equivalent to Diffusion.DataTypes.JSON.BinaryDeltaType.Diff(original, this) .

ToJSONString()

Returns this JSON value as a JSON-formatted string.

Declaration
string ToJSONString()
Returns
Type Description
System.String

This JSON value as a JSON-formatted string.

Validate()

Checks whether this instance is valid.

Declaration
IJSON Validate()
Returns
Type Description
IJSON

The current IJSON instance to allow fluent chaining.

Remarks

Convenient equivalent to Diffusion.DataTypes.JSON.Validate(this) .

Back to top