Skip to content

Add Operation

EnderTurret edited this page Nov 5, 2024 · 1 revision

The add patch type adds a value to an element, possibly overwriting an existing value. A similar operation is the replace operation, which replaces an existing element.

An add patch looks like this:

{
  "op": "add", // specifies this is an add patch
  "path": "/path/to/added/element", // specifies the path to the added element, i.e. where to put the value
  "value": "some element to add" // the thing to add
}

The add operation can be used to add something to an object, like so:

// overworld.json.patch
{
  "op": "add",
  "path": "/respawn_anchor_works",
  "value": true
}
// overworld.json (patched)
{
  // ...
  "respawn_anchor_works": true // added by file/OverworldRespawnAnchors
}

It can also be used to add something to an array:

// blue_dye_from_cornflower.json.patch
{
  "op": "add",
  "path": "/ingredients/-", // the - here means to add at the end of the array; specifying a number will try to add it to that position, shifting anything that comes after
  "value": {
    "tag": "realisticcrafting:mortar_and_pestles"
  }
}
// blue_dye_from_cornflower.json (patched)
{
  // ...
  "ingredients": [
    {
      "item": "minecraft:cornflower"
    },
    { // added by mod/Realistic Crafting
      "tag": "realisticcrafting:mortar_and_pestles"
    }
  ],
  // ...
}

For objects, the add operation will replace an existing element if necessary:

// fall.json
{
  // ...
  "exhaustion": 0
}
// fall.json.patch
{
  "op": "add",
  "path": "/exhaustion",
  "value": 0.1
}
// fall.json (patched)
{
  // ...
  "exhaustion": 0.1 // added by file/FallDamageExhaustion
}

Clone this wiki locally