9

I need help with a specific command that I am using in a new game that I am creating inside of Minecraft. The command I have so far is:

/give @p sign 1 0 {BlockEntityTag:{Text1:"{"text":"
[MF2]","color":"gold","clickEvent":
{"action":"run_command","value":"tellraw @a ["",{"text":"[MF2] 
","color":"gold"},{"selector":"@p","color":"dark_aqua"},{"text":" is now an
admin of the server!","color":"white"}]"}}",Text3:"{"text":"Click to join
Admin","color":"dark_aqua","clickEvent":
{"action":"run_command","value":"scoreboard teams join admin @p"}}"},display:
{Name:"Custom Sign"}}

If I take out the /tellraw command, the command works fine, but I need the inner command to announce to the game that a new admin has joined.

With /tellraw inside, the error message reads:

Data tag parsing failed: Unexpected token t at:

text":"[MF2]","color":"gold","clickEvent":{"action":"run_command","value":"tellraw
  @a [""{"text":"[MF2] ","color":"gold"},
  {"selector":"@p","color":"dark_aqua"},{"text":" is now an admin 
  of the server!","color":"white"}]"}}",Text3:"{"text":"Click to join
  Admin","color":"dark_aqua","clickEvent":
  {"action":"run_command","value":"scoreboard teams join admin @p"}}"

If anyone knows how to fix this, please let me know.


Related:

2 Answers 2

9

Look at this particular part, which is causing the first error:

Text1:"{"text
  1. Minecraft reads Text:, and is expecting a string (surrounded with quotation marks) to follow
  2. Minecraft reads ", so starts reading the string to go with Text1 (the key)
  3. Minecraft reads { as the string
  4. Minecraft reads ", so stops reading the string, and is now expecting a comma to start the next key-value pair, e.g: Text1:"Hello",Text2:"World"
  5. Minecraft finds t instead, so throws the unexpected token error

To fix this, you need to escape (put a backslash before) quotation marks that are part of the JSON. \" tells Minecraft to read " just as another character in the string, rather than stopping reading the string, as the " is part of the JSON rather than the top-level NBTData.

Even more confusing is when you have a tellraw command, requiring JSON, within the sign's text JSON. You now need to escape the backslash itself (\\) before the quotation mark (\") so that it's not read as NBTData, nor as the sign's text JSON, but as part of a string within the sign's text JSON.

Fully fixed command:

/give @p sign 1 0 {BlockEntityTag:{Text1:"{\"text\":\"[MF2]\",\"color\":\"gold\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"tellraw @a [{\\\"text\\\":\\\"[MF2] \\\",\\\"color\\\":\\\"gold\\\"},{\\\"selector\\\":\\\"@p\\\",\\\"color\\\":\\\"dark_aqua\\\"},{\\\"text\\\":\\\" is now an admin of the server!\\\",\\\"color\\\":\\\"white\\\"}]\"}}",Text3:"{\"text\":\"Click to join Admin\",\"color\":\"dark_aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"scoreboard teams join admin @p\"}}"},display:{Name:"Custom Sign"}}

In the future, use a generator, or use a trigger/scoreboard command to set off the tellraw command, as this can get pretty confusing and annoying to find errors in.

1

An updated solution that adds on to this other solution.

In 1.14 and above, you can reduce the need for escape characters by surrounding your whole string with single quotes ' instead of double quotes ". This means that you can freely include "s in your string without escaping them with \s. However, this means that you will need to escape every ' in your string.

Example:

/give @s dirt{display:{Name:'[{"text":"Hello, World!"}]'}}

Note that single and double quoted strings with the same text are considered equivalent. However, Minecraft now uses single-quoted strings for all strings containing JSON text components. This is evident because using /data get always shows JSON text components as single-quoted strings, no matter which format was used to type them out.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .