How could I insert a command into a command block using blockdata if it contains quotation marks (like this: " ) (JE 1.12.2)? [duplicate]

I tried to run a command like this:

/blockdata 1 2 3 {Command:"summon minecraft:area_effect_cloud ~ ~ ~ {Tags:["sg"]}"}

And then it replied it was expecting } but got s at ...Tags:["s<---HERE

By the way I am making music having a rondeau theme using command blocks, and I don't want to build the theme multiple times. I was wondering if it could be solved by just changing the command in the end of the frase once it was repeated in order to trigger the next frase.

Is it possible to execute such command?


"Escaping" is the official term for what you want.

To put a quotation mark (") into a string, you use this: \"
To put a backslash (\) into a string, you use this: \\

So this means that a string in a string in a string looks like this*:

"first string \"second string \\\"third string\\\" second string\" first string"

Minecraft also allows you to use ' as the outer and " as the inner string limiter, that way you don't need to escape anything on that second level (a string in a string) and you only need a single backslash for the third level (a string in a string in a string).

(*This can get crazily long, for example I once made a one-command creation in a complicated way that also placed signs. Some of the quotation marks needed to be escaped with fifteen backslashes.)