{{redirect|JSON component|the item components used on [[commands]] in {{BE}}|Item components}} '''Raw JSON text''' is the format Minecraft uses to send and display rich text to players. It can also be sent by players themselves using commands and [[data pack]]s. Raw JSON text is written in {{wikipedia|JSON}}, a human-readable data format. == Java Edition == Raw JSON text 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 raw JSON text component can be a {{nbt|string}} JSON string, {{nbt|list}} JSON array or a {{nbt|compound}} JSON object. Strings and arrays are both shorthand for longer object structures, as described below.
"A"
and {"text": "A"}
are equivalent.
* {{nbt|list}} A list of raw JSON text components. Same as having all components after the first one appended to the first's {{nbt|list|extra}} array. For example, ["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.
* {{nbt|compound}} A text component object. All non-content tags are optional.
**'''''Content'''''
*** {{nbt|string|type}}: Optional. Specifies the content type. One of {{code|[[#Plain Text|"text"]]}}, {{code|[[#Translated Text|"translatable"]]}}, {{code|[[#Scoreboard Value|"score"]]}}, {{code|[[#Entity Names|"selector"]]}}, {{code|[[#Keybind|"keybind"]]}}, or {{code|[[#NBT Values|"nbt"]]}}.
*** If {{nbt|string|type}} is not present, has an invalid value, or if the required tags for the specified type are not present, the type is determined automatically by checking the object for the following tags: [[#Plain Text|{{nbt|string|text}}]], [[#Translated Text|{{nbt|string|translate}}]], [[#Scoreboard Value|{{nbt|compound|score}}]], [[#Entity Names|{{nbt|string|selector}}]], [[#Keybind|{{nbt|string|keybind}}]], and finally [[#NBT Values|{{nbt|string|nbt}}]]. If multiple are present, whichever one comes first in that list is used.
*** Values specific to each content type are described [[#Content types|below]].
** '''''Children'''''
*** {{nbt|list|extra}}: A list of additional raw JSON text components to be displayed after this one.
**** A child text component. Child text components inherit all formatting and interactivity from the parent component, unless they explicitly override them.
** '''''Formatting'''''
*** {{nbt|string|color}}: Optional. Changes the color to render the content in the text component object and its child objects. If not present, the parent color will be used instead. The color is specified as a color code or as a color name.
****"# "
, where
is a [[wikipedia:Web_colors#Hex_triplet|6-digit hexadecimal color]], changes the color to #"black"
changes the color to {{color|#000000}}
****"dark_blue"
changes the color to {{color|#0000AA}}
****"dark_green"
changes the color to {{color|#00AA00}}
****"dark_aqua"
changes the color to {{color|#00AAAA}}
****"dark_red"
changes the color to {{color|#AA0000}}
****"dark_purple"
changes the color to {{color|#AA00AA}}
****"gold"
changes the color to {{color|#FFAA00}}
****"gray"
changes the color to {{color|#AAAAAA}}
****"dark_gray"
changes the color to {{color|#555555}}
****"blue"
changes the color to {{color|#5555FF}}
****"green"
changes the color to {{color|#55FF55}}
****"aqua"
changes the color to {{color|#55FFFF}}
****"red"
changes the color to {{color|#FF5555}}
****"light_purple"
changes the color to {{color|#FF55FF}}
****"yellow"
changes the color to {{color|#FFFF55}}
****"white"
changes the color to {{color|#FFFFFF}}
*** {{nbt|string|font}}: Optional. The resource location of the [[Resource pack#Fonts|font]] for this component in the resource pack within assets//font
. Defaults to "minecraft:default"
.
*** {{nbt|boolean|bold}}: Optional. Whether to render the content in bold.
*** {{nbt|boolean|italic}}: Optional. Whether to render the content in italics. Note that text that is italicized by default, such as custom item names, can be unitalicized by setting this to false
.
*** {{nbt|boolean|underlined}}: Optional. Whether to underline the content.
*** {{nbt|boolean|strikethrough}}: Optional. Whether to strikethrough the content.
*** {{nbt|boolean|obfuscated}}: Optional. Whether to render the content obfuscated.
** '''''Interactivity'''''
*** {{nbt|string|insertion}}: Optional. When the text is shift-clicked by a player, this string is inserted in their chat input. It does not overwrite any existing text the player was writing. This only works in chat messages.
*** {{nbt|compound|clickEvent}}: Optional. Allows for events to occur when the player clicks on text. Only work in chat messages and [[written book]]s, unless specified otherwise.
****{{nbt|string|action}}: The action to perform when clicked. Valid values are:
***** "open_url"
: Opens {{nbt|string|value}} as a URL in the user's default web browser.
***** "open_file"
: Opens the file at {{nbt|string|value}} on the user's computer. This is used in messages automatically generated by the game (e.g., on taking a screenshot) and cannot be used by players for security reasons.
***** "run_command"
: Works in signs, but ''only'' on the root text component, not on any children. Activated by {{control|using}} the sign. In chat and written books, this has {{nbt|string|value}} entered in chat as though the player typed it themselves and pressed enter. However, this can only be used to run commands that do not send chat messages directly (like {{cmd|say}}, {{cmd|tell}}, and{{cmd|teammsg}}). Since they are being run from chat, commands must be prefixed with the usual "/" slash, and player must have the required permissions. In [[sign]]s, the command is run by the server at the sign's location, with the player who {{control|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, are not restricted by chat length limits, and do not need to be prefixed with a "/" slash.
***** "suggest_command"
: Opens chat and fills in {{nbt|string|value}}. If a chat message was already being composed, it is overwritten. This does not work in books.{{bug|MC-70317|||Works as Intended}}
***** "change_page"
: Can only be used in written books. Changes to page {{nbt|string|value}} if that page exists.
***** "copy_to_clipboard"
: Copies {{nbt|string|value}} to the clipboard.
**** {{nbt|string|value}}: The URL, file path, chat, command or book page used by the specified action.
*** {{nbt|compound|hoverEvent}}: Optional. Allows for a tooltip to be displayed when the player hovers their mouse over text.
**** {{nbt|string|action}}: The type of tooltip to show. Valid values are:
***** "show_text"
: Shows a raw JSON text component.
***** "show_item"
: Shows the tooltip of an item as if it was being hovering over it in an inventory.
***** "show_entity"
: Shows an entity's name, type, and UUID. Used by {{nbt|string|selector}}.
**** {{nbt|compound|contents}}: The formatting of this tag varies depending on the action.
***** For "show_text"
: Another raw JSON text component. Can be any valid text component type: string, array, or object. Note that {{nbt|compound|clickEvent}} and {{nbt|compound|hoverEvent}} do not function within the tooltip.
***** For "show_item"
: The item stack whose tooltip that should be displayed.
****** {{nbt|string|id}}: The item's [[resource location]]. Defaults to {{code|minecraft:air}} if invalid.
****** {{nbt|int|count}}: Optional. Size of the item stack. This typically does not change the content tooltip.
****** {{nbt|compound|components}}: Optional. Additional information about the item. See [[Data component format|item components]].
***** For "show_entity"
: The entity whose tooltip should be displayed.
****** {{nbt|compound|name}}: Optional. Hidden if not present. A raw JSON text that is displayed as the name of the entity.
****** {{nbt|string|type}}: A string containing the type of the entity, as a [[resource location]]. Defaults to {{code|minecraft:pig}} if invalid.
****** {{nbt|string|}}{{nbt|list|id}}: The [[UUID]] of the entity. Either:
******* A string representing the UUID in the hyphenated hexadecimal format. Must be a valid UUID.
******* A list of four numbers representing the UUID in int-array format. As this is JSON and not SNBT there is no dedicated integer array type, so the int-array format looks like {{code|[1,1,1,1]}} rather than {{code|[I;1,1,1,1]}}. Fractional numbers and numbers outside the 32-bit integer range will be truncated. Booleans are also permitted, with {{code|true}} and {{code|false}} converting to 1 and 0 respectively.
**** {{nbt|string}}{{nbt|list}}{{nbt|compound|value}}: Deprecated, use {{nbt|compound|contents}} instead. The formatting and type of this tag varies depending on the action.
***** For "show_text"
: Another raw JSON text component. Can be any valid text component type: string, array, or object. Note that {{nbt|compound|clickEvent}} and {{nbt|compound|hoverEvent}} do not function within the tooltip.
***** For "show_item"
: A string containing the SNBT for an item stack. See {{slink|Player.dat format|Item structure}}.
***** For "show_entity"
: A string containing SNBT. The SNBT does not represent the full entity data, but only stores the name, type, and UUID of the entity.
****** {{nbt|string|name}}: Optional. Hidden if not present. An NBT string containing some JSON that is parsed as a text component and displayed as the name of the entity.
****** {{nbt|string|type}}: Optional. An NBT string containing the type of the entity, as a [[resource location]]. Defaults to {{code|minecraft:pig}} if invalid or missing.
****** {{nbt|string|id}}: An NBT string containing the UUID of the entity in the hyphenated hexadecimal format. Must be a valid UUID.
%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).Selecting the "next" argument ignores slots that specify an index explicitly. So if the translation text "Hello %s, %2$s, and %s." was given the components "John" and "Becky", it would display "Hello John, Becky, and Becky." For example, the built-in English language file contains the translation "chat.type.advancement.task": "%s has made the advancement %s",
.
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).Showing the reader's own score only works in situations where a message has one singular reader. That is chat messages, [[Commands/title|/title
s]], and [[Written book|written books]]. It does not work for [[bossbar]] display names or blocks like signs.
*** {{nbt|string|objective}}: The internal name of the objective to display the player's score in.
show_entity
action, and a {{nbt|compound|clickEvent}} tag with the suggest_command
action (if the entity is a player) added to it to provide the functionality described above. If any of these tags are already present on the original component being resolved, the tag on the original component will be used.
* If more than one entity is found by the selector, the component is resolved into an empty {{nbt|string|text}} component, with an {{nbt|list|extra}} list containing the individual entity name components (each resolved as in the single entity case) separated by copies of the {{nbt|any|separator}} component (or its default, if not present).
* If no entities are found by the selector, the component is resolved into an empty {{nbt|string|text}} component.
|-
|}
{"color": "gray", "text": ", "}
. A raw JSON text component. Used as the separator between different names, if the component selects multiple entities.
{"keybind": "key.inventory"}
displays "e" if the player is using the default control scheme.
{"text": ", "}
. A raw JSON text component. Used as the separator between different tags, if the component selects multiple tags.
** {{nbt|string|block}}: A string specifying the coordinates of the block entity from which the NBT value is obtained. The coordinates can be absolute, [[Commands#Tilde and caret notation|relative]], or local. Ignored if {{nbt|string|nbt}} is not present.
** {{nbt|string|entity}}: A string specifying the [[Selector|target selector]] for the entity or entities from which the NBT value is obtained. Ignored if {{nbt|string|nbt}} is not present.
** {{nbt|string|storage}}: A string specifying the [[resource location]] of the [[command storage]] from which the NBT value is obtained. Ignored if {{nbt|string|nbt}} is not present.
/tellraw
]] and [[Commands/title|/title
]]. It can also be done by the [[Item modifier|item modifers]] '''set_name''' and '''set_lore''', but only if their {{nbt|string|entity}} tag is set. Custom item names, custom entity names and [[scoreboard]] objective names cannot by themselves resolve these components.
Additionally, resolution fixes a single value in place. Therefore, these content types are not dynamic, and don't update to reflect changes in their environment, while "simple" components usually do.
== Bedrock Edition ==
%%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.
**** '''''Content:'' Scoreboard Value''' ''[[#Component resolution|(requires resolution)]]''
**** {{nbt|compound|score}}: Displays a score holder's current score in an objective. Displays nothing if the given score holder or the given objective do not exist, or if the score holder is not tracked in the objective.
*****{{nbt|string|name}}: The name of the score holder whose score should be displayed. This can be a [[selector]] like @p or an explicit name. If the text is "*"
, 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).Showing the reader's own score only works in situations where a message has one singular reader. That is chat messages, [[Commands/titleraw|/titleraw
]]s, and [[written book]]s.{{verify}} It doesn't work for things like signs that can have more than one "reader".{{verify}}
***** {{nbt|string|objective}}: The internal name of the objective to display the player's score in.
**** '''''Content:'' Entity Names''' ''[[#Component resolution|(requires resolution)]]''
**** {{nbt|string|selector}}: A string containing a [[selector]]. Displayed as the name of the player or entity found by the selector. If more than one player or entity is found by the selector, their names are displayed in either the form "Name1 and Name2" or the form "Name1, Name2, Name3, and Name4". 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.
"color":"#ff0088"
).}}
|{{HistoryLine||1.19.4|dev=23w03a|Added text component {{code|fallback}}.}}
|{{HistoryLine||1.20.3|dev=23w40a|Added text component {{code|type}}.
|{{code|contents.id}} field in {{code|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 {{code|text}} component.
|Several errors that used to be ignored are now hard errors.}}
|{{HistoryLine|||dev=23w42a|Changes to chat component serialization: components of type nbt
now have source
field with allowed values: {{cd|d=and|entity|block|storage}}.}}
|{{HistoryLine||1.21.2|dev=24w33a|Invalid selector
patterns in chat components will now cause commands to fail to parse, instead of resolving to an empty string.}}
|{{HistoryLine||1.21.4|dev=24w44a|Added optional shadow_color
style field to Text Components, which overrides the shadow properties of text.}}
|{{HistoryLine|bedrock}}
|{{HistoryLine||1.9.0|dev=beta 1.9.0.0|Added {{cmd|tellraw}}, the raw JSON text used to support this command.}}
|{{HistoryLine||1.16.100|dev=beta 1.16.100.55|Added text component {{code|score}} and {{code|selector}}.}}
}}
== See also ==
* [[JSON]]
* [[Commands]]
* [[Formatting code]]
== External links ==
* [https://misode.github.io/text-component/ Text component Generator on misode.github.io]
== Notes ==
{{Notelist}}
== References ==
{{Reflist}}
[[Category:Development]]
== Navigation ==
{{Navbox Java Edition technical|general}}
{{Navbox Bedrock Edition}}
[[de:JSON-Text]]
[[ja:Raw JSONテキストフォーマット]]
[[pt:Formato de texto JSON bruto]]
[[zh:文本组件]]