The immutable JSON data value.
public interface IJSON : IBytes
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.
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
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.
Applies a binary delta to this JSON value to create a new value.
IJSON Apply(IBinaryDelta delta)
The binary delta to apply to this JSON value.
The new JSON value.
Convenient equivalent to Apply(Object, Object).
Compares this JSON value with an earlier version to create a binary delta.
IBinaryDelta BinaryDiff(IJSON original)
The original JSON value.
The delta representing the difference between original and this JSON.
Convenient equivalent to Diff(Object, Object).
Returns this JSON value as a JSON-formatted string.
This JSON value as a JSON-formatted string.
Checks whether this instance is valid.
The current IJSON instance to allow fluent chaining.
Convenient equivalent to Validate(Object).