JSON
The DataSource JSON data type is the recommended way to deliver JavaScript Object Notation (JSON) documents to front end applications.
Requirements
To use the JSON data type, your Caplin components and libraries must be at least as recent as the versions listed in the table below:
Product | Minimum Version |
---|---|
C DataSource API |
7.1.9 |
Java DataSource API |
7.1.9 |
.NET DataSource API |
7.1.9 |
Liberator |
7.1.8 |
Transformer |
7.1.5 |
StreamLink iOS |
7.1.0 |
StreamLink Android |
7.1.1 |
StreamLink Java |
7.1.1 |
StreamLink JS |
7.1.1 |
StreamLink .NET |
7.1.1 |
Overview
JavaScript Object Notation (JSON) is a text-based data interchange format that supports complex, nested data structures. Developers of Caplin Platform web applications often use JSON to transport data that does not translate easily to the key-value pairs of a Caplin Platform record.
Prior to the introduction of the JSON data type, developers could transport a JSON document in a Caplin Platform record field. This approach could not take advantage of the Caplin Platform’s optimisations for updating records. When the JSON changed, the field had to be resent in its entirety, which made it inefficient for large JSON documents.
With the introduction of the JSON data type, the Caplin Platform now provides first class support for transporting JSON data.
Features
The JSON data type has the following advantages over transporting JSON in a record field:
IETF RFC 6902 support
The Caplin Platform implements JSON update messages using the IETF RFC 6902 standard to describe an update in terms of a JSON patch.
An example JSON patch is shown below:
In the example above, the JSON patch is only 12 bytes smaller than the full JSON document, but for small changes to larger JSON documents the difference in size can be much greater. This difference can result in significant savings in bandwidth.
JSON patches are supported by DataSource components and StreamLink clients:
-
The Java DataSource API’s
CachingPublisher
in conjunction with aJSONHandler
implementation publishes updates as JSON patches when the patch size is smaller than the full image size. provides a method for creating an update message from a raw JSON patch. See the MessageFactory.createJsonImageMessage method. -
Liberator and Transformer can receive and apply a JSON patch to a cached JSON object.
-
StreamLink clients can receive JSON patches and apply them to a native object.
Liberator: optimal choice of JSON message type over RTTP
For cached JSON documents below 512KB in size, Liberator automatically determines and uses the optimal message type (image or update) to send JSON data to StreamLink clients:
-
When Liberator receives a JSON image that it can more optimally stream to StreamLink clients as an update, Liberator will stream the message as an update.
-
When Liberator receives a JSON update that it can more optimally stream to StreamLink clients as an image, Liberator will stream the message as an image.
Liberator: chunked streaming of large JSON messages over RTTP
Liberator streams a JSON message to a client in chunks, which prevents a large JSON message from delaying the delivery of smaller, high-frequency messages such as price updates.
The rate at which Liberator adds a JSON message’s chunks to an outbound queue is bandwidth adaptive. Adding chunks to an outbound queue faster than the queue is moving would be counter-productive and provide fewer opportunities for other messages to be queued between the chunks. Liberator queues a chunk only if at least a chunk-sized amount of data has been sent to the client since the previous chunk was queued.
StreamLink API support
The StreamLink API provides the following interfaces to support the JSON data type:
-
JsonHandler interface
-
JsonEvent interface
For example code, see Subscribing to a JSON subject.
Java DataSource API support
The Java DataSource API provides the following interfaces and methods to support the JSON data type:
-
CachingPublisher
interface -
JsonHandler
interface, with example implementationsJacksonJsonHandler
andGsonJsonHandler
. -
JsonMessage
interface
For example code, see Publishing a JSON subject.
See also: