NBT path format

An NBT path is a descriptive label used to specify a collection of particular elements from an NBT data tree. A path has the general form, where each   declares what types of sub-elements can be chosen from a previous tag.

Node
These are all seven types of nodes available.

The tags collection start with only one element (i.e. the root tag) and changes along the nodes on the path. NBT path consumers operate on the final collection of the tags.

In the path, (dot/period) characters separate the nodes. The nodes can be mixed and matched, except the root node with object must be the first in the path when it is present.

Name escaping
The valid character set (without quote) for a path seems to be all non-whitespace characters, as long as any opening brackets and braces ( and  ) are closed and at the end of each term (that is, followed by nothing but a period or the end of the path—  or  ). That being said, the "reasonable character set" for defining a data tag includes all ASCII lowercase and uppercase letters, digits, underscore, period, and square and curly brackets (Regular expression: )

Quoted strings, such as, may be used if a name of a key needs to be escaped.

Mixed path

 * —Specifies the root tag
 * —Specifies the root tag if the "foo" subtag is set to
 * —Specifies the tag named "foo" under the root tag
 * or —Specifies foo's subtag named "bar".
 * —Specifies the first element of the list (or array) "bar"
 * —Specifies the last element of the list (or array) "bar"
 * —Specifies the subtag named "A [crazy name]!" under that first element
 * —Specifies the subtag named "baz" under that crazily named tag
 * —Specifies all elements of the list (or array) "bar"
 * —Specifies the subtags named "baz" under all elements of the list "bar"
 * —Specifies all elements of the list "bar", in which the "baz" tag is set to
 * —Specifies the "foo" tag if its subtag "bar" has the value
 * —Specifies the "bar" tag if it matches the value

Example 1
These names have been arbitrarily picked, for demonstrative purposes.


 * —Specifies the subtag named "foo" under the root tag.
 * —Specifies foo's child named "bar".
 * —Specifies the first element of the list "bar"
 * —Specifies the child named "A [crazy name]!" under that first element
 * —Specifies the child named "baz" under that crazily named element

The tree structure
 * The root entity data
 * : The "foo" element
 * : The "bar" element
 * The first element of list "bar"
 * : The "A [crazy name]!" element
 * : The "baz" element; the target element of this example.
 * Another unrelated element in list "bar"

Example 2
A player has written a book and placed it inside a chest at their feet, and are going to work up to the above command in stages. Observe the following imaginary chat log:


 * {| class="collapsible collapsed collapse-button-none" data-description="bookInAChest_example"

! style="text-align:left" | Chat log * Alex jumps on top of a chest. * Alex runs the command: /data get block ~ ~ ~ 0 55 0 has the following block data: {{{TAG_number|x|0}},, , Items : [{{{TAG_number|Slot|0|b}}, , }, {{{TAG_number|Slot|9|b}}, , , tag : { pages : [ '{"text":"\'twas brillig and the slithy toves"}' , '{"text":"Did gyre and gimble in the wabe."}' , '{"text":"All mimsy were the borogoves,"}' , '{"text":"And the mome raths outgrabe."}' ], , }}], } ''* Alex only wants to look at the chest's inventory. They could search the Official Minecraft Wiki for what the name of that tag is, but because they understand how to read NBT format they decide to figure it out from that last command's output.'' * Alex runs the command: /data get block ~ ~ ~ Items 0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items:  [{{{TAG_number|Slot|0|b}},, }, {{{TAG_number|Slot|9|b}}, , , tag : { pages : [ '{"text":"\'twas brillig and the slithy toves"}' , '{"text":"Did gyre and gimble in the wabe."}' , '{"text":"All mimsy were the borogoves,"}' , '{"text":"And the mome raths outgrabe."}' ], , }}] , id: "minecraft:chest"} ''* Alex wants to narrow this down to the second item in the chest. Counting from 0, the second item would be element 1.'' * Alex runs the command: /data get block ~ ~ ~ Items[1] 0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{Slot: 0b, id: "minecraft:clock", Count: 1b},  {{{TAG_number|Slot|9|b}},, , tag : { pages : [ '{"text":"\'twas brillig and the slithy toves"}' , '{"text":"Did gyre and gimble in the wabe."}' , '{"text":"All mimsy were the borogoves,"}' , '{"text":"And the mome raths outgrabe."}' ], , }} ], id: "minecraft:chest"} * Alex wants just the "tag" tag. * Alex runs the command: /data get block ~ ~ ~ Items[1].tag 0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{Slot: 0b, id: "minecraft:clock", Count: 1b}, {Slot: 9b, id: "minecraft:written_book", Count: 1b, tag:  { pages : [ '{"text":"\'twas brillig and the slithy toves"}', '{"text":"Did gyre and gimble in the wabe."}' , '{"text":"All mimsy were the borogoves,"}' , '{"text":"And the mome raths outgrabe."}' ], , } }], id: "minecraft:chest"} * Alex wants just the "pages" tag. * Alex runs the command: /data get block ~ ~ ~ Items[1].tag.pages 0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{Slot: 0b, id: "minecraft:clock", Count: 1b}, {Slot: 9b, id: "minecraft:written_book", Count: 1b, tag: {pages:  [ '{"text":"\'twas brillig and the slithy toves"}', '{"text":"Did gyre and gimble in the wabe."}' , '{"text":"All mimsy were the borogoves,"}' , '{"text":"And the mome raths outgrabe."}' ] , author: "LewisCarroll", title: "Jabberwocky"}}], id: "minecraft:chest"} * Alex wants just the fourth element from this list. * Alex runs the command: /data get block ~ ~ ~ Items[1].tag.pages[3]  0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{Slot: 0b, id: "minecraft:clock", Count: 1b}, {Slot: 9b, id: "minecraft:written_book", Count: 1b, tag: {pages: ['{"text":"\'twas brillig and the slithy toves"}', '{"text":"Did gyre and gimble in the wabe."}', '{"text":"All mimsy were the borogoves,"}',  '{"text":"And the mome raths outgrabe."}' ], author: "LewisCarroll", title: "Jabberwocky"}}], id: "minecraft:chest"} * Alex has what they need now, and uses the paths they have gathered to edit the book from outside the chest. ''* Alex runs the command: /data modify block ~ ~ ~ Items[1].tag.pages[3] set value '{"text":"And this pig here\'s named Babe."}' Modified block data of 0 55 0 ''* Alex runs the command: /data modify block ~ ~ ~ Items[1].tag.pages prepend value '{"text":"Call me Ishmael."}' Modified block data of 0 55 0 ''* Alex runs the command: /data modify block ~ ~ ~ Items[1].tag.author set value "Cthulhu the Sleeper"
 * }

NBT路径格式