Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ChangeMap

An unmodifiable map describing the changes to a JSON value.

The JSONDelta.inserted method returns a ChangeMap describing the parts of the second JSON value not found in the first JSON value. Similarly, JSONDelta.removed returns a ChangeMap describing the parts of the first JSON value not found in the second JSON value.

The map contains an entry for each change, as follows:

  • The key is a JSON Pointer syntax reference locating the change in the complete value. Since a JSON value is a list of zero or more data items, the reference always begins with an array index. For example, the first part is identified by the JSON Pointer /0.
  • The value is part of the complete value. It is returned as a parsed value.

An error will be thrown if an invalid JSON pointer expression is passed to get, containsKey, descendants, or intersection. This only occurs if the expression does not start with / and is not empty.

Hierarchy

  • ChangeMap

Index

Methods

containsKey

  • containsKey(pointer: string): boolean
  • Determines if this change map contains an entry for a given JSON Pointer

    throws

    an error if pointer is an invalid JSON Pointer expression

    Parameters

    • pointer: string

      the JSON Pointer expression

    Returns boolean

    true if an entry exists, false if not

descendants

  • Returns a view of the portion of this map whose keys are descendants of pointer. If pointer is contained in this map, it will be included in the result.

    throws

    an error if pointer is an invalid JSON Pointer expression

    Parameters

    • pointer: string

      the json pointer expression to derive descendants for

    Returns ChangeMap

    changemap of descendant changes

entrySet

  • entrySet(): Array<object>
  • Returns an array of map entries. Each entry is in the form of a key/value object pair.

    The key is a JSON Pointer expression, in string form. The value will be parsed from the underlying JSON object.

    Returns Array<object>

    the entry array

    Example:

    changeMap.entrySet().forEach(function(entry) {
        console.log(entry.key, entry.value);
    });

get

  • get(pointer: string): any
  • Retrieve a value from this change map, identified by a JSON Pointer.

    throws

    an error if pointer is an invalid JSON Pointer expression

    Parameters

    • pointer: string

      the JSON Pointer expression

    Returns any

    the change map value, if it exists, otherwise null

intersection

  • Returns a view of the portion of this map whose keys are descendants or parents of pointer. If pointer is contained in this map, it will be included in the result.

    This method can be used to determine whether a structural delta affects a particular part of a JSON value. For example:

    if (structuralDelta.removed().intersection("/contact/address").length) {
      // The structural delta removes elements that affect '/contact/address'.
    }
    if (structuralDelta.inserted().intersection("/contact/address").length) {
      // The structural delta inserts elements that affect '/contact/address'.
    }
    throws

    an error if pointer is an invalid JSON Pointer expression

    Parameters

    • pointer: string

      the json pointer expression to derive intersection for

    Returns ChangeMap

    changemap of intersection changes