![]() |
VOOZH | about |
The text component format, historically also known as raw JSON text, is used by Minecraft to send and display rich-text to players. It can also be sent by players themselves using commands (such as /tellraw and /title) and data packs.
Text components are written in SNBT, for example {text: "Hello world"}. They are used for rich-text formatting in written books, signs, custom names and the /tellraw, /title, /bossbar, /scoreboard and /team commands.
The format is made up of text components. There is a single root component, which can have child components, which can have their own children and so on. Components can also have formatting and interactivity added to them, which is inherited by their children.
A component can be a [String] string, [NBT List / JSON Array] list or a [NBT Compound / JSON Object] object. Strings and lists are both shorthand for longer object structures, as described below.
"A" and {text: "A"} are equivalent.["A", "B", "C"] is equivalent to {text: "A", extra: ["B", "C"]}. Note that because the later components are actually children of the first one, any formatting applied to the first component is inherited by the later ones. For example, [{text: "A", color: "red"}, "B", "C"] will display all three letters with red text."text", "translatable", "score", "selector", "keybind", or "nbt"."#<hex>", where <hex> is a 6-digit hexadecimal color, changes the color to #<hex>"black" changes the color to "dark_blue" changes the color to "dark_green" changes the color to "dark_aqua" changes the color to "dark_red" changes the color to "dark_purple" changes the color to "gold" changes the color to "gray" changes the color to "dark_gray" changes the color to "blue" changes the color to "green" changes the color to "aqua" changes the color to "red" changes the color to "light_purple" changes the color to "yellow" changes the color to "white" changes the color to assets/<namespace>/font. Defaults to "minecraft:default".false.Due to the [NBT List / JSON Array] extra tag, the above format may be recursively nested to produce complex and functional text strings. However, a text component doesn't have to be complicated at all: virtually all properties are optional and may be left out.
Text components can display several types of content. These tags should be included directly into the text component object.
Displays plain text.
"text".Displays a translated piece of text from the currently selected language. This uses the client's selected language, so if players with their games set to different languages are logged into the same server, each will see the component in their own language.
Translations are defined in language files in resource packs, including the built-in resource pack.
Translations can contain slots for text that is not known ahead of time, such as player names. When displaying the translated text, slots will be filled from a provided list of text components. The slots are defined in the language file, the translate key, the fallback key and generally take the form %s (displays the next component in the list), or %3$s (displays the third component in the list; replace 3 with whichever index is desired).[note 1] For example, the built-in English language file contains the translation "chat.type.advancement.task": "%s has made the advancement %s",.
"translatable".Displays a score from the scoreboard.
| Requires component resolution. |
|---|
| This component is resolved into a [String] text component containing the scoreboard value. |
"score".limit=1. If the text is "*", it shows the reader's own score (for example, /tellraw @a {score: {name: "*", objective: "obj"}} shows every online player their own score in the "obj" objective).[note 2]Displays the name of one or more entities found by a selector.
If exactly one entity is found, the entity's name is displayed by itself. If more are found, their names are displayed in the form "Name1, Name2, Name3", with gray commas. If none are found, the component is displayed as no text.
Hovering over a name shows a tooltip with the name, type, and UUID of the target. Clicking a player's name suggests a command to whisper to that player. Shift-clicking a player's name inserts that name into chat. Shift-clicking a non-player entity's name inserts its UUID into chat.
| Requires component resolution. |
|---|
|
"selector".{color: "gray", text: ", "}. A text component. Used as the separator between different names, if the component selects multiple entities.Displays the name of the button that is currently bound to a certain configurable control. This uses the client's own control scheme, so if players with different control schemes are logged into the same server, each will see their own keybind.
"keybind".{keybind: "key.inventory"} displays "e" if the player is using the default control scheme. As a fallback it displays the translation if it exists.Displays NBT values from entities, block entities, or command storage.
By default, NBT values are displayed as SNBT, with special coloring added to the SNBT keys and values. If [Boolean] plain is set to true, no special coloring is added. If [Boolean] interpret is set to true, the game will attempt to interpret the NBT value as a text component instead of showing it as SNBT. If [Boolean] interpret is true and the NBT value is not a valid text component, it is displayed as no text. If more than one NBT value is found, either by selecting multiple entities or by using a multi-value path, they are displayed in order, with the [Undefined] separator value between them.
| Requires component resolution. |
|---|
|
"nbt"."block", "entity", and "storage", corresponding to the source of the NBT data.{text: ", "}. A text component. Used as the separator between different tags, if the component selects multiple tags.Displays objects as single sprites in component messages. Sprites are rendered as 8ร8-pixel squares. This will ignore bold and italic styles!
When specifying [String] object as "atlas", it displays a single sprite from a texture atlas as a character.
"object" if object-specific keys are detected."atlas" (Optional as it defaults to "atlas" if not specified)"minecraft:blocks"."block/emerald_block").When specifying [String] object as "player" it displays the 2D face sprite of a player profile.
"object" if object-specific keys are detected."player"profile data component. If specified as a string, it corresponds to [String] name.
true)Text component resolution is the process of converting "advanced" (server-side) text components into "simple" (client-side) text components so that they can be displayed to the user.
Certain text component types, such as text, translate, keybind, and object, can be directly displayed by a player client, as the client does not need any additional information to interpret them. Those are known as "client-side" or "simple" text components.
Other types, such as score, selector, and nbt, require additional work from the server before they can be displayed by the client. Those are known as "server-side" or "advanced" text components. As the client does not have access to the information that these text components are meant to display, they need to be resolved by the server, which involves retrieving appropriate data from the world and replacing the server-side text components with client-side ones which the client knows how to render.
If the client receives unresolved server-side text components, score and nbt text components display as empty text, but selector text components display the selector itself.
Additionally, text component resolution fixes a single value in place based on the appropriate data at the moment of resolution. Therefore, these content types are not dynamic, and don't update to reflect later changes. For example, {score:{name:"@p",objective:"points"}} may resolve to "100", and will stay that way even if the player's "points" score increases or decreases.
Text component resolution can be done in many ways:
/tellraw and /title.text tag./bossbar set <id> name while the command is executing as an entity./scoreboard objectives modify <objective> displayname while the command is executing as an entity./scoreboard players display name while the command is executing as an entity.fixed text component using /scoreboard players display numberformat or /scoreboard objectives modify <objective> numberformat fixed while the command is executing as an entity.There are several places where text components are not automatically resolved, such as:
custom_name, item_name, lore, and written_book_content. The previously mentioned item modifiers can be used to resolve text components when writing to these data components.CustomName tag.Click events control what happens when the player clicks on the text. Can be one of the following:
Opens the specified URL in the user's default web browser.
open_urlOpens the specified file on the user's computer. This is used in messages automatically generated by the game (e.g., on taking a screenshot) and cannot be sent by servers for security reasons.
open_fileRuns the specified command. This runs as if the player typed the specified command in chat and pressed enter. However, this can only be used to run commands that do not send chat messages directly (like /say, /tell, and /teammsg). Since they are being run from chat, the player must have the required permissions.
On signs, the command is run by the server at the sign's location, with the player who used the sign as the command executor (that is, the entity selected by @s). Since they are run by the server, sign commands have the same permission level as a command block instead of using the player's permission level, and are not restricted by chat length limits.
run_command/ slash.Opens chat and fills in the specified text or command. If a chat message was already being composed, it is overwritten.This does not work in books.[2]
suggest_commandCan only be used in written books. Changes to the specified page if that page exists.
change_pageCopies the specified text to the clipboard.
copy_to_clipboardOpens the specified dialog.
Sends a custom event to the server; has no effect on vanilla servers.
customHover events control what happens when the player hovers over the text. Can be one of the following:
Shows a text component.
show_textShows the tooltip of an item as if it was being hovering over it in an inventory.
show_itemminecraft:air if invalid.Shows an entity's name, type, and UUID. Used by [String] selector.
show_entity[I;1,1,1,1] or [1,1,1,1].Unlike Java Edition, text components in Bedrock Edition are written in JSON.
%%1 (displays the first argument; replace 1 with whichever index is desired). If no argument is provided for a slot, the slot is not displayed."*", it shows the reader's own score (for example, /tellraw @a { "rawtext" : [ { "score" : { "name" : "*" , "objective" : "obj"} } ] } shows every online player their own score in the "obj" objective).[note 5]/tellraw @a { "rawtext" : [ { "text" : "Hello world" } ] }This sends a message to all players saying "Hello World" in English only. See the Translate action to see how to send localized texts.
Raw text takes in an array of text objects. Each object in the list is added to the previous object. For example, /tellraw @a { "rawtext" : [ { "text":"Hello" }, { "text" : " World" } ] }
outputs the same "Hello World" as the first example. Appending text can be useful to combine 2 different localized texts, or apply different colors to each word etc.
You can go down a line by using "\n". For example,
/tellraw @a { "rawtext" : [ { "text" : "Hello\nNext line" } ] }
The translate object allows creators to provide localized text to users. If translate is specified along with text, translate overrides the text object. The string to provide to translate is the name of the string in the language files. For example, in Vanilla Minecraft "commands.op.success" is the string that displays when /op is used on a player successfully.
/tellraw @a { "rawtext": [ { "translate" : "commands.op.success" } ] }
This outputs "Opped %s" to all players. Note that because of text being ignored with translate specified, the following example outputs the same text:
/tellraw @a { "rawtext" : [ { "text":"Hello World", "translate":"commands.op.success" } ] }
In the translate example above, it outputs "Opped %s". To have a name or other text show up instead of %s, "with" needs to be specified as well. Note that "with" only works with "translate" and also requires an array [] instead of curly brackets {} .
/tellraw @a { "rawtext": [ { "translate" : "commands.op.success", "with": [ "Steve" ] } ] }
If you want to use a translated text inside the "with" component, instead of an array it needs to be another rawtext component (which consists of an array of text components). The following example outputs "Opped Apple".
/tellraw @a { "rawtext": [ { "translate" : "commands.op.success", "with": { "rawtext": [ { "translate" : "item.apple.name" } ] } } ] }
"translate" and "%s" can be used without needing a corresponding string in the localization files. For example:
/tellraw @a { "rawtext": [ { "translate" : "Hello %%s", "with": [ "Steve" ] } ] }
This outputs "Hello Steve" to all players.
%%s can be used multiple times. They are filled in, in the order specified
/tellraw @a { "rawtext": [ { "translate" : "Hello %%s and %%s", "with": [ "Steve", "Alex" ] } ] }
Outputs: "Hello Steve and Alex"
You can again use a rawtext component to replace the plain string array, like so
/tellraw @a { "rawtext": [ { "translate" : "Hello %%s and %%s", "with": { "rawtext" : [ { "text" : "Steve" }, { "translate" : "item.apple.name" } ] } } ] }
Outputs: "Hello Steve and Apple"
The order to fill in %%s can be changed by instead specifying it with %%#, replacing # with an actual number. For example, to swap the position of Steve and Alex in the above example, instead run the following:
/tellraw @a { "rawtext" : [ {"translate" : "Hello %%2 and %%1", "with": [ "Steve", "Alex"] } ] }
Outputs: "Hello Alex and Steve"
String formatting is still possible, but not using the text component format used in Java Edition. Instead, formatting codes are used to change text color and style.
| Java Edition | |||||||
|---|---|---|---|---|---|---|---|
| 1.7.2 | 13w37a | Added /tellraw, which supports raw JSON text. | |||||
| 1.8 | 14w02a | Added text component insertion. | |||||
| 14w07a | Added text component score. | ||||||
| 14w20a | Added /title, which supports raw JSON text.
| ||||||
Added text component selector. | |||||||
| 14w25a | Now supported by signs and written books. | ||||||
| 1.12 | 17w16a | Added text component keybind. | |||||
| 1.13 | 18w01a | Now supported by custom entity names. | |||||
| 18w05a | Added /bossbar. The argument <name> supports raw JSON text. | ||||||
| pre8 | Now supported by scoreboard objective names and team names. | ||||||
| 1.14 | 18w43a | Added text component nbt with block and entity.
| |||||
Now supported by the item tag Lore. | |||||||
| 18w44a | Added text component interpret. | ||||||
| 1.15 | 19w39a | Added storage for the nbt text component. | |||||
| 19w41a | Added the action copy_to_clipboard for the text component clickEvent. | ||||||
| 1.16 | 20w17a | Added text component font.
| |||||
Added argument contents for hoverEvent, replacing value, which is now deprecated but still supported.
| |||||||
The color component can now contain a hexadecimal RGB value prefixed by # (Example: "color":"#ff0088"). | |||||||
| 1.19.4 | 23w03a | Added text component fallback. | |||||
| 1.20.3 | 23w40a | Added text component type.
| |||||
contents.id field in show_entity can represent the UUID as an array of ints.
| |||||||
Numbers and booleans are no longer auto-converted to strings, and so are invalid for the text component.
| |||||||
| Several errors that used to be ignored are now hard errors. | |||||||
| 23w42a | Changes to chat component serialization: components of type nbt now have source field with allowed values: entity, block, and storage. | ||||||
| 1.21.2 | 24w33a | Invalid selector patterns in chat components will now cause commands to fail to parse, instead of resolving to an empty string. | |||||
| 1.21.4 | 24w44a | Added optional shadow_color style field to Text Components, which overrides the shadow properties of text. | |||||
| 1.21.5 | 25w02a | Text components are now stored as NBT and are passed into commands using SNBT. | |||||
The hoverEvent field has been renamed to hover_event.
| |||||||
The clickEvent field has been renamed to click_event.
| |||||||
| 25w03a | The text field in show_text action has been renamed to value. | ||||||
| 1.21.6 | 25w20a | Click Events: New click action minecraft:custom has been added. | |||||
Dialog Click Event: New action show_dialog has been added. | |||||||
| 1.21.9 | 25w32a | Added new text component with type object. | |||||
| 25w34a | Bold and italics styles are ignored when drawing sprites. | ||||||
| 25w35a | Object text component has been updated to support displaying other non-character objects as a part of text. | ||||||
| 26.1 | snap8 | minecraft:nbt: Tags resolved with the minecraft:nbt text component when the interpret field is set to false are now pretty-printed instead of being flattened into a single text component. Contents of the nbt and block fields are no longer silently rejected when parsing fails. The field entity no longer accepts trailing data after a selector. A new option called plain has been added to remove styling from pretty-printed text. | |||||
minecraft:selector: The field selector no longer accepts trailing data after a selector. | |||||||
| pre1 | minecraft:object: Added a new optional field named fallback. | ||||||
| pre2 | Components in server status messages (MotD) nested more than 16 times will now be discarded and replaced with an ellipsis. | ||||||
| Bedrock Edition | |||||||
|---|---|---|---|---|---|---|---|
| 1.9.0 | beta 1.9.0.0 | Added /tellraw, the raw JSON text used to support this command. | |||||
| 1.16.100 | beta 1.16.100.55 | Added text component score and selector. | |||||
/titles, and written books. It does not work for bossbar display names or blocks like signs.
/titleraws, and written books.[verify] It doesn't work for things like signs that can have more than one "reader".[verify]