SNBT: writing Minecraft NBT as text

SNBT is the text form of NBT used in commands like /give, /summon and /data. Learn the type suffixes, arrays, quoting rules and what changed in Java 1.21.5.

SNBT (stringified NBT) is NBT written as text. You meet it in commands, in the output of /data get, and in the editor's SNBT text view, which shows a whole file this way. It looks like JSON, but every number carries its type, and that is the part people trip over.

A short example

{
  Slot: 0b,
  id: "minecraft:diamond_sword",
  count: 1,
  components: {
    "minecraft:damage": 12,
    "minecraft:enchantments": {"minecraft:sharpness": 3}
  }
}

This is one inventory stack. Slot is a Byte because of the b, count is an Int because a whole number without a suffix is an Int, and the keys containing a colon are quoted.

Numbers and their suffixes

TypeWriteNotes
BByte5btrue and false also give a Byte 1 or 0
SShort5s
IInt5The default for whole numbers
LLong5LNeeded for anything beyond ±2,147,483,647
FFloat5.0f
DDouble5.0 or 5.0dThe default for decimal numbers

Suffixes are not case-sensitive: 5L and 5l mean the same. The editor writes Longs with a lowercase l, which the game accepts.

Strings, lists, compounds and arrays

  • Strings go in double or single quotes: "minecraft:stone". A string made only of letters, digits, _, -, . and + may skip the quotes, but quoting is never wrong.
  • Compounds use braces: {name: "Steve", level: 30}. Keys follow the same quoting rule as strings, so "minecraft:damage" needs quotes because of the colon.
  • Lists use brackets: [1.0, 64.0, 1.0]. In the file, all items share one type.
  • Arrays start with a type letter and a semicolon: [B; 1b, 0b], [I; 1, 2, 3], [L; 1L, 2L]. Player and entity UUIDs are Int arrays of four numbers, and must be written with the I; prefix.

What changed in Java 1.21.5

The 1.21.5 snapshots extended the syntax used by commands. If you write SNBT for a current version, you can use:

  • Lists that mix types, such as ["a", {b: 3}]. In the saved file they are still stored as a single-type list, with each item wrapped in a compound.
  • Hexadecimal and binary numbers (0xFF, 0b101), and exponents (1.2e3).
  • More escape sequences in quoted strings, including \n, \t and Unicode escapes such as ❤.
  • Two operations: bool(…), which turns a value into true or false, and uuid("…"), which turns a UUID in text form into the matching Int array.

The same release switched text components in commands such as /tellraw from JSON to SNBT. Older guides that show JSON text in commands need adjusting.

SNBT in commands

/summon minecraft:zombie ~ ~ ~ {PersistenceRequired: 1b, CustomName: "Gate guard"}
/give @s minecraft:diamond_sword[enchantments={"minecraft:sharpness": 5}]
/data get entity @s Inventory

The first line passes a compound of entity data. The second sets an item component, whose value is SNBT. The third prints your inventory as SNBT, which you can paste into the editor or compare with a file.

Using the SNBT view in the editor

  1. Open a file in the editor and click SNBT text above the tree.
  2. Edit the text directly, or select part of it and copy it into a command.
  3. Switch back to Tree, or download: the text is checked and applied first. A syntax error is reported with its position and nothing is lost.

The SNBT view is the quickest way to change a value's type: replace 5 with 5L and the value becomes a Long. You can also download the whole file as .snbt text, and open .snbt files to turn them back into binary NBT.

Ready to edit?Open the file in the editor: every value keeps its NBT type and the file is saved in its original format.