Raw JSON text format

From Minecraft Wiki
Jump to: navigation, search

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 packs. Raw JSON text is written in JSON, a human-readable data format.

Java Edition[edit]

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 will be inherited by their children.

A raw JSON text component can be any JSON data type, including JSON string, JSON array, JSON object, JSON boolean, JSON number, and JSON null. The game treats booleans and numbers as strings. Null value can't be parsed as a command argument, but is valid for NBT. Strings and arrays are both shorthand for longer object structures, as described below.

  • A string containing plain text to display directly. This is the same as an object that only has a  text tag. For example, "A" and {"text": "A"} are equivalent.
  • A boolean is converted to a string ("true" or "false") to display directly. This is the same as an object that only has a  text tag. For example, true, "true", and {"text": "true"} are equivalent.
  • A number is converted to a string to display directly. This is the same as an object that only has a  text tag. For example, 1.9E10, "1.9E10", and {"text": "1.9E10"} are equivalent.
  • A null value is converted to an empty string. This is the same as an object that only has a  text tag. For example, , "", and {"text": ""} are equivalent.
  • A list of raw JSON text components. Same as having all components after the first one appended to the first's  extra array.[1] For example, ["A", "B", "C"] is equivalent to {"text": "A", "extra": ["B", "C"]}.
  • A text component object. To be valid, an object must contain one content tag: text, translate, score, selector, keybind, or nbt. Having more than one is allowed, but only one will be used.[2] All non-content tags are optional.
    • Content: Plain Text
    •  text: A string containing plain text to display directly. Can also be a number or boolean that is displayed directly.
    • Content: Translated Text
    •  translate: A translation identifier, to be displayed as the corresponding text in the player's selected language. If no corresponding translation can be found, the identifier itself will be used as the translation text. This identifier is the same as the identifiers found in lang files from assets or resource packs.
    •  with: Optional. A list of raw JSON text component arguments to be inserted into slots in the translation text. Ignored if  translate is not present.
      • Translations can contain slots for text that is not known ahead of time, such as player names. These slots are defined in the translation text itself, not in the JSON text component, and generally take the form %s (displays the next argument) or %1$s (displays the first argument; replace 1 with whichever index is desired).[3] If no argument is provided for a slot, the slot will not be displayed.
    • Content: Scoreboard Value (requires resolution)
    •  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.
      •  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 a selector, the selector must be guaranteed to never select more than one entity, possibly by adding 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).[4]
      •  objective: The internal name of the objective to display the player's score in.
      •  value: Optional. If present, this value is used regardless of what the score would have been.
    • Content: Entity Names (requires resolution)
    •  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 will show 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.
    • Content: Keybinds
    •  keybind: A keybind identifier, to be displayed as the name of the button that is currently bound to a certain action. For example, {"keybind": "key.inventory"} will display "e" if the player is using the default control scheme.
    • Content: NBT Values (requires resolution)
    •  nbt: The NBT path used for looking up NBT values from an entity, a block entity or an NBT storage. NBT strings display their contents. Other NBT values are displayed as SNBT with no spacing or linebreaks. How values are displayed depends on the value of  interpret. If more than one NBT value is found, either by selecting multiple entities or by using a multi-value path, they are displayed in the form "Value1, Value2, Value3, Value4". Requires one of block, entity, or storage. Having more than one is allowed, but only one will be used.[5]
    •  interpret: Optional, defaults to false. If true, the game will try to parse the text of each NBT value as a raw JSON text component. This usually only works if the value is an NBT string containing JSON, since JSON and SNBT are not compatible. If parsing fails, displays nothing. Ignored if  nbt is not present.
    •  block: A string specifying the coordinates of the block entity from which the NBT value is obtained. The coordinates can be absolute or relative. Ignored if  nbt is not present.
    •  entity: A string specifying the target selector for the entity or entities from which the NBT value is obtained. Ignored if  nbt is not present.
    •  storage: A string specifying the namespaced ID of the command storage from which the NBT value is obtained. Ignored if  nbt is not present.
    • Children
    •  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
    •  color: Optional. The color to render the content in. Valid values are "black", "dark_blue", "dark_green", "dark_aqua", "dark_red", "dark_purple", "gold", "gray", "dark_gray", "blue", "green", "aqua", "red", "light_purple", "yellow", "white", and "reset" (cancels out the effects of colors used by parent objects).
      Set to "#<hex>" to insert any color in the hexadecimal color format. Example: Using "#FF0000" makes the component red. Must be a full 6-digit value, not 3-digit.
    •  font: Optional. The resource location of the font for this component in the resource pack within assets/<namespace>/font. Defaults to "minecraft:default".
    •  bold: Optional. Whether to render the content in bold.
    •  italic: Optional. Whether to render the content in italics. Note that text which is italicized by default, such as custom item names, can be unitalicized by setting this to false.
    •  underlined: Optional. Whether to underline the content.
    •  strikethrough: Optional. Whether to strikethrough the content.
    •  obfuscated: Optional. Whether to render the content obfuscated.
    • Interactivity
    •  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.
    •  clickEvent: Optional. Allows for events to occur when the player clicks on text. Only work in chat messages and written books, unless specified otherwise.
      •  action: The action to perform when clicked. Valid values are:
        • "open_url": Opens  value as a URL in the user's default web browser.
        • "open_file": Opens the file at  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 using the sign. In chat and written books, this has  value entered in chat as though the player typed it themselves and pressed enter. This can be used to run commands, provided the player has the required permissions. Since they are being run from chat, commands must be prefixed with the usual "/" slash. In signs, the command is run by the server at the sign's location, with the player who used the sign as @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  value. If a chat message was already being composed, it is overwritten.
        • "change_page": Can only be used in written books. Changes to page  value if that page exists.
        • "copy_to_clipboard": Copies  value to the clipboard.
      •  value: The URL, file path, chat, command or book page used by the specified action.
    •  hoverEvent: Optional. Allows for a tooltip to be displayed when the player hovers their mouse over text.
      •  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  selector.
      •  value: The formatting and type of this tag varies depending on the action. Deprecated, use  contents instead.
        • show_text: Another raw JSON text component. Can be any valid text component type: string, array, or object. Note that clickEvent and hoverEvent do not function within the tooltip.
        • show_item: A string containing the SNBT for an item stack. See Player.dat format#Item structure.
        • 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.
          •  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. If the NBT string cannot be parsed as a text component, the entire tooltip is replaced with the text "Invalid Entity!"
          •  type: Optional. Hidden if not present. An NBT string containing some plain text that is displayed as the type of the entity. Can be any text.
          •  id: Optional. Shown as empty line if not present. An NBT string containing some plain text that is displayed as the UUID of the entity. Can be any text.
      •  contents: The formatting of this tag varies depending on the action.
        • show_text: Another raw JSON text component. Can be any valid text component type: string, array, or object. Note that clickEvent and hoverEvent do not function within the tooltip.
        • show_item: The item that should be displayed.
          •  id: The namespaced item ID. Present minecraft:air if invalid.
          •  count: Optional. Size of the item stack.
          •  tag: Optional. A string containing the serialized NBT of the additional information about the item, discussed more in the subsections of the player format page.
        • show_entity: The entity that should be displayed.
          •  name: Optional. Hidden if not present. A raw JSON text that is displayed as the name of the entity.
          •  type: A string containing the type of the entity. Should be a namespaced entity ID. Present minecraft:pig if invalid.
          •  id: A string containing the UUID of the entity in the hyphenated hexadecimal format. Should be a valid UUID.

Due to the extra tag, the above format may be recursively nested to produce very complex and functional text strings. However, a raw JSON text doesn't have to be complicated at all: virtually all properties are optional and may be left out.

Component resolution[edit]

Certain text content types (score, selector, and nbt) will not work in all contexts. These content types need to be resolved, which involves retrieving the appropriate data from the world, rendering it into "simple" text components, and replacing the "advanced" text component with that. This resolution can be done by signs, by written books when they are first opened, and by commands such as /tellraw and /title. It can also be done by the loot table functions set_name and set_lore, if and only if their entity tag is set. Custom item names and custom entity names cannot by themselves resolve these components.

Additionally, resolution will fix a single value in place. Therefore, these content types are not dynamic, and will not update to reflect changes in their environment, while "simple" components usually will.

Bedrock Edition[edit]

Unlike in Java Edition, the raw JSON text in Bedrock Edition is more strict and simple.

  • The root tag.
    •  rawtext: A list contains all text object.
      • The base chat component object.
        •  text: A string representing raw text to display directly in chat. Note that selectors such as "@a" and "@p" are not translated into player names; "\n" is newline (enter). Ignored when  translate exist in the object.
        •  translate: The translation identifier of text to be displayed using the player's selected language. This identifier is the same as the identifiers found in lang files from assets or resource packs.
        •  with: A list of string arguments to be used by  translate. Useless otherwise.
          • The arguments are text corresponding to the arguments used by the translation string in the current language, in order (for example, the first list element corresponds to "%%1" in a translation string).
Basic raw text example
/tellraw @a { "rawtext" : [ { "text" : "Hello world" } ] }

This will send a message to all players saying "Hello World". However this will only be in English, see the Translate action to see how to send localized texts.

Appending[edit]

Raw text takes in an array of text objects. Each object in the list will be 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.

Translate[edit]

The translate object allows creators to provide localized text to users. If translate is specified along with text, translate will override 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 will output "Opped %s" to all players. Note that because of text being ignored with translate specified, the following example will output the same text:

/tellraw @a { "rawtext" : [ { "text":"Hello World", "translate":"commands.op.success" } ] }

With[edit]

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" ] } ] }

%%s[edit]

"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.

Multiple %s[edit]

%%s can be used multiple times. They will be filled in, in the order specified

/tellraw @a { "rawtext": [ { "translate" : "Hello %%s and %%s", "with": [ "Steve", "Alex" ] } ] }

Outputs: "Hello Steve and Alex"

Ordering with %%#[edit]

The order to fill in %s to be filled in 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"

History[edit]

Java Edition
1.7.213w37aAdded /tellraw, the raw JSON text used to support this command.
1.814w02aAdded text component insertion.
14w07aAdded text component score.
14w20aAdded /title, that supported by raw JSON text.
Added text component selector.
14w25aNow supports the signs and the written books.
1.1217w16aAdded text component keybind.
1.1318w01aNow supports the custom names.
18w05aAdded /bossbar, The argument <name> supported by raw JSON text.
1.1418w43aAdded text component nbt, block and entity.
Now supports the item lore tag.
18w44aAdded text component interpret.
1.1519w39aAdded text component storage.
19w41aAdded the action copy_to_clipboard for the text component clickEvent.
1.1620w17aAdded 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").
Bedrock Edition
1.9.0beta 1.9.0.0Added /tellraw, the raw JSON text used to support this command.

References[edit]

  1. Note that because the later components are actually children of the first one, any formatting applied to the first component will be inherited by the later ones. For example, [{"text": "A", "color": "red"}, "B", "C"] would display all three letters with red text.
  2. Content tags are checked in the order text, translate, score, selector, keybind, nbt. If multiple are present, whichever one comes first in that list will be used.
  3. 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 arguments "John" and "Becky", it would display "Hello John, Becky, and Becky."
  4. Showing the reader's own score only works in situations where a message has one singular reader. That is chat messages, /titles, and written books. It doesn't work for things like signs that can have more than one "reader".
  5. NBT sources are checked in the order block, entity, storage. If multiple are present, whichever one comes first in that list will be used.

See also[edit]