Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface JSONDelta

Structural delta type for JSON.

A JSONDelta describes the differences between two JSON values. Unlike a binary delta, a structural delta can be queried to determine its effect. The removed and inserted methods provide full details of the differences between the two values.

An instance can be created from two JSON values using JSON.jsonDiff.

JSONDeltas are useful for identifying small changes to complex JSON values. Here's an example of how to use this class to filter interesting changes in a ValueStream.

const valueStream = session.addStream('foo/bar', diffusion.datatypes.json());
valueStream.on('value', (topicPath, oldValue, newValue) => {
    const delta = newValue.diff(oldValue);

    if (!delta.removed().intersection('/address').isEmpty() ||
        !delta.inserted().intersection('/address').isEmpty()) {

        // The 'address' field has changed.
        processAddress(newValue);
    }
  }

  // ...
}
author

DiffusionData Limited

since

5.9

Hierarchy

  • JSONDelta

Index

Methods

hasChanges

  • hasChanges(): boolean
  • Returns whether the two JSON values used to create this instance are different.

    Returns boolean

    true if this delta has an effect

inserted

  • Returns the parts of the second JSON value not found in the first JSON value.

    Returns ChangeMap

    the removed parts. The JSON Pointer references used for the keys are relative to second JSON value.

removed

  • Returns the parts of the first JSON value not found in the second JSON value.

    Returns ChangeMap

    the removed parts. The JSON Pointer references used for the keys are relative to first JSON value.