Table of Contents

Interface IJSON

Namespace
PushTechnology.ClientInterface.Data.JSON
Assembly
Diffusion.Client.dll

The immutable JSON data value.

public interface IJSON : IBytes
Inherited Members

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.

IJSON Apply(IBinaryDelta delta)

Parameters

delta IBinaryDelta

The binary delta to apply to this JSON value.

Returns

IJSON

The new JSON value.

Remarks

BinaryDiff(IJSON)

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

IBinaryDelta BinaryDiff(IJSON original)

Parameters

original IJSON

The original JSON value.

Returns

IBinaryDelta

The delta representing the difference between original and this JSON.

Remarks

ToJSONString()

Returns this JSON value as a JSON-formatted string.

string ToJSONString()

Returns

string

This JSON value as a JSON-formatted string.

Validate()

Checks whether this instance is valid.

IJSON Validate()

Returns

IJSON

The current IJSON instance to allow fluent chaining.

Remarks