Skip to main content

SNBT

SNBT, otherwise know as Stringified NBT, is a way to write NBT data in a string. We've modified and extended the existing idea of SNBT as used in vanilla Minecraft to allow for more flexibility and ease of use. FTB primarily uses SNBT for the following:

  • Config files
  • Data files
  • Some internal communication between mods

FTB's implementation of SNBT is pretty much compatible with vanilla SNBT, although FTB SNBT supports multiline structures, and does not require commas to delimit objects in such multiline structures.

Why SNBT?

Why don't we just use Forge's night-config system like any other mod does? Or one of the multiple config libraries for Fabric? Our mods are cross-platform, and there isn't one single config mod that would work everywhere. So, we have our own system, as part of FTB Library. As for why SNBT in particular; it's based on an existing vanilla format, and the config files it uses are easily human-readable, and close enough to the familiar JSON format to be easy to pick up, while also offering a few improvements over JSON.

What does it look like

SNBT is very similar to JSON, with a few key differences. The following is an example of a config file:

{
# Boolean test 3
# Default: false
"test 3": false,

# Default: true
test_1: true

# Boolean test 2
# Default: true
test_2: true

# Group comment test
# Line 2
sub_test: {
# Default: false
boolean: false

# Default: 0.5d
# Range: 0.0d ~ 1.0d
double: 1.0d

# Default: 50
# Range: 30 ~ +∞
int: 30

# Default: "hello"
string: "hello"

# Default: [ 1, 2, 3 ]
list: [ 1, 2, 3 ]
}
}

Json vs SNBT

The following is a comparison between JSON and SNBT:

FeatureJSONSNBTNotes
CommentsNoYesStart comments with a # symbol
Trailing commasNoOptionalCommas are not optional in multi-line sections; they are required if multiple elements are on the same line, e.g. a: { b: 1, c: 2}
Unquoted keysNoYesKeys must be quoted if they contain whitespace, e.g. { "my key": 3 }
Unquoted valuesNoNoValues must be quoted if they contain whitespace, e.g. { key: "some value" }
Single quoted stringsNoYes
Specific number typesNoYesSee Types section below for accepted numeric suffixes
Nested ObjectsYesYesE.g. a: { b: [ 1, 2, 3 ], c: { x: 10, y: 20 } }
Nested ArraysYesYes
Short hand value mappingNoYes

Types

SNBT supports the following types (see Vanilla documentation for more info):

TypeNotes
BooleanUse unquoted true and false values (if quoted they are treated as String)
DoubleSuffix the numeric value with d or D, e.g. 123.45D. Exponential notation accepted, e.g. 1.23e-6d
FloatSuffix the numeric value with f or F, e.g. 123.45F. Exponential notation accepted.
Long64-bit value; suffix with l or L
Integer32-bit value; no suffix required, just a number
Short16-bit value; suffix with s or S
Byte8-bit value; suffix with b or B
StringString values are single-or double quoted
Object(In the form of a nested SNBT object)
ArrayArrays are surrounded with square brackets, e.g. [1, 2, 3 ]
∞ (Infinity)Maps to Java Double.POSITIVE_INFINITY. Variants include -∞, ∞F and -∞F for negative and float equivalents.
NaN (Not a Number)Maps to Java Double.NaN. Also, NanF maps to Float.NaN