How would I setblock multiple command blocks in a row that have commands in them? [duplicate]

I need help with a specific command that I am using in a new game that I am creating inside of Minecraft. The command 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 then the command works fine, but I need the command in there to announce to the game that a new admin has joined.

With the tellraw command, the error message is the following:

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.


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.