Skip to content

Sort arrays and apply patches

Sorting reorders the elements of an array, and a JSON Patch applies a list of changes, such as the differences found in the Compare view. Each is one edit of a file you can edit, and one undo restores the original.

  1. Select an array in the tree and choose Node → Sort Array…, or right-click it and choose Sort Array….

  2. In Sort by member, type or pick the key to sort objects by, such as price. To sort numbers or strings by their own value, leave it empty.

  3. Choose the Direction: Ascending or Descending.

  4. Choose how to Compare as:

    • Auto: by type first, in the order the option shows, then by value. Capital letters sort before small ones.
    • Numeric: like Auto, but a string that holds a number, such as "10", sorts as that number.
    • Text: everything as text, ignoring case.
  5. Select Sort.

Elements that do not have the member go last, in both directions. Each element is moved as it is, with its formatting, so only the order changes. Very large arrays cannot be sorted; see Limits.

A JSON Patch is a list of operations, such as add, remove, replace, move, copy, and test, each with a JSON Pointer path:

[
{ "op": "replace", "path": "/settings/timeout", "value": 30 },
{ "op": "remove", "path": "/settings/legacy" }
]
  1. Choose File → Apply JSON Patch….

  2. Paste the patch into Patch (JSON), or select From file… to load it from a .json file. Paths start at the document root.

  3. Read the preview under the box: the number of operations, and which part of the document they rewrite. Errors appear there too, for example op 2: /settings/legacy does not exist.

  4. Select Apply, or press Ctrl+Enter.

The operations run in order, and the patch applies completely or not at all: if one operation fails, for example a test, nothing changes.

JSON Digger changes the smallest object or array that holds every operation and leaves the rest of the file as it is. Inside that object or array, members the patch does not touch keep their exact bytes, and key order is kept. A new value is written as the patch spells it, in the file’s indentation and line endings; a moved or copied value is laid out afresh in the same style. Of two members with the same key, a patch acts on the first.

To apply the differences found in the Compare view, use Apply to document there; it opens this dialog with the patch filled in. See Copy or apply the differences.