Commands/data

The /data command allows the user to get, merge, modify, and remove NBT data of a block entity, entity, or Command NBT storage.

Syntax
There are four instructions for /data (get, merge, modify, remove), and the targets/sources referenced by each instruction command may be either block , entity, or.


 * /data ...
 * ... (block 
 * Read off the entire NBT data or the subsection of the NBT data from the targeted block position or entity to the executor with syntax highlighting, scaled by if specified.
 * Read off the entire NBT data or the subsection of the NBT data from the targeted block position or entity to the executor with syntax highlighting, scaled by if specified.


 * ... (block 
 * Merge the NBT data from the target block position or entity with the specified data.
 * Merge the NBT data from the target block position or entity with the specified data.


 * {{code|... append from (block
 * {{code|... (block {{!}}entity {{!}}storage ) }}
 * Removes NBT data at from the targeted block position or entity. Player NBT data cannot be removed.
 * Removes NBT data at from the targeted block position or entity. Player NBT data cannot be removed.

Syntax displayed in various ways
 * {| class="collapsible collapsed collapse-button-none" data-description="simple_tree"

! style="text-align:left" | Simplified tree:
 * {{code|/data}}
 * {{code|… get  [ ] [ ]}}
 * {{code|… merge  }}
 * {{code|… modify   }}
 * {{code|… from  [
 * To set the armor attribute of the dolphin closest to coordinates (0, 64, 0) to 20:
 * To change the first item in a chest located at coordinates (1, 64, 1) into a diamond block, keeping all NBT data:
 * {{code|/data modify block 1 64 1 Items[0].id set value "minecraft:diamond_block"}}
 * To make the nearest zombie have a 80% chance to drop items in its off-hand when it dies, and never drop items in the main hand:
 * To make the nearest zombie have a 80% chance to drop items in its off-hand when it dies, without affecting the chance for the main hand:
 * {{code|1=/data modify entity @e[type=zombie,limit=1,sort=nearest] HandDropChances[1] set value 0.8f}}
 * To make the nearest zombie have a 80% chance to drop items in its off-hand when it dies, and never drop items in the main hand:
 * To make the nearest zombie have a 80% chance to drop items in its off-hand when it dies, without affecting the chance for the main hand:
 * {{code|1=/data modify entity @e[type=zombie,limit=1,sort=nearest] HandDropChances[1] set value 0.8f}}
 * {{code|1=/data modify entity @e[type=zombie,limit=1,sort=nearest] HandDropChances[1] set value 0.8f}}

Storage
The command storage of NBT data is an efficient way for commands to access or save NBT data without an overhead for block entities or entities reading from or writing to the NBT data.

Each command storage is a general purpose, key-value storage, identified by a resource location to prevent unintentional conflicts.

and can read from the storage, while, , , and  can write to the storage.

The command storage is accessible with JSON text as well.