NBT Path
NBT paths specify one or more tags in an NBT tree. Java Edition only.
Usage
A path is node.node....node (dots separate nodes; some dots may be omitted, see below). Each node selects child tags from the current tag set (initially just the root). Nodes apply to every element of the set; all selected children form the new set. The final set is the path's result.
/data get ...(and similar) requires the result set to have exactly one tag./data modify ...allows sets larger than one.
Nodes
Six node types (the root compound node must be first; others arrange freely):
- Root compound node —
{}selects the root tag (if compound). - Named tag node —
fooselects the child tag namedfoo. Quote the name when it contains., whitespace, or quotes:'a.b','a b','"name"',"\"te's't". Quoting: use'...'or"..."; embedded quotes must be escaped (e.g."\"te's't"). - Compound matching node —
foo{bar:"baz"}selects thefoochild only if it is a compound whosebarequals"baz"; a bare{foo:4.0f}at path start selects the root only iffoois4.0f(usable mid-path too:foo{bar:"baz"}.bar). - List index node —
[0]selects the element at index 0 (0-based);[-1]selects the last element (negative indexes count from the end). - List index range node —
[0..2]selects elements 0 through 2 inclusive (ranges can be open-ended:[..2],[1..]). - List matching node —
[{baz:5b}]selects all list elements that are compounds matching the given structure.
Dots before [-style nodes can be omitted: tag2.[] == tag2[].
Semantics Examples
Given {tag1:1b, tag2:[{foo:0},{foo:[]},{foo:{}}]}:
tag2→ the list[{foo:0},{foo:[]},{foo:{}}].tag2.[]→ three compounds.tag2.[].foo→0,[],{}(each applied to every element).foo.bar[]— all elements ofbar;foo.bar[].baz— thebazchildren of all compound elements;foo.bar[{baz:5b}]— all compound elements havingbaz:5b.
Full Example
/data get block ~ ~ ~ Items[1].components.minecraft:written_book_content.pages[3].raw walks: Items → [1] (second item) → components → minecraft:written_book_content → pages → [3] (fourth page) → raw. The same path works with /data modify ... set value ... for editing (e.g. changing the author or prepending a page).