Class: JSON

diffusion.datatypes. JSON

new JSON()

Immutable JSON data. The value is stored internally as a buffer.

To create an instance from an object, obtain a diffusion.datatypes.JSONDataType implementation from diffusion.datatypes.json() and call diffusion.datatypes.JSONDataType#parse.

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.

Since:
  • 5.7

Extends

Methods

apply(delta) → {DataTypes.JSON}

Apply a delta to this JSON value to create a new value.

Convenient equivalent to: diffusion.datatypes.JSON().deltaType(delta).apply(this, delta);

Parameters:
Name Type Description
delta Object The binary delta to apply to this value
Throws:
Error if the delta is invalid
Returns:
A new instance derived from applying the delta to this value
Type
DataTypes.JSON

diff(original, type) → {diffusion.datatypes.BinaryDelta}

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

Convenient equivalent to: diffusion.datatypes.json().deltaType(type).diff(original, this);

Standard JSON objects may also be provided as the value to diff instead of a diffusion.datatypes.JSON instance.

Parameters:
Name Type Argument Default Description
original diffusion.datatypes.JSON | Object The value to diff against this
type String <optional>
"binary" The type of delta to generate
Returns:
A delta representing the difference between this and the provided value
Type
diffusion.datatypes.BinaryDelta
Examples
var binaryDelta = jsonValue.diff({ foo : "bar" });
var jsonDelta = jsonValue.diff({ foo : "bar" }, "json");

get() → {Object}

Get the value as a JSON object
Returns:
The JSON value
Type
Object

jsonDiff(original) → {diffusion.datatypes.JSONDelta}

Compare this JSON value with an earlier version to create a structural json delta.

Convenient equivalent to: this.diff(original, "json");

Standard JSON objects may also be provided as the value to diff instead of a diffusion.datatypes.JSON instance.

Parameters:
Name Type Description
original diffusion.datatypes.JSON | Object The value to diff against this
Returns:
A delta representing the difference between this and the provided value
Type
diffusion.datatypes.JSONDelta
Example
var delta = jsonValue.jsonDiff({ foo : "bar" });