Setblock command block with command [duplicate]
Solution 1:
You have to escape special characters when inside quotation marks.
In this case Command
is a string so it's data is inside quotation marks. Inside that string is id
which is another string. In your case you have that within quotation marks. The inner quotation marks have to be escaped.
Here is the command with escaped quotation marks:
/setblock ~ ~ ~ minecraft:command_block 11 replace {Command:"/summon Item ~ ~ ~ {Item:{id:\"iron_ingot\",Count:1,tag:{}}}"}
While I don't recommend it, you can also omit the quotations around the id data and it functions properly in 1.12.2:
/setblock ~ ~ ~ minecraft:command_block 11 replace {Command:"/summon Item ~ ~ ~ {Item:{id:iron_ingot,Count:1,tag:{}}}"}
You can also specify the data type for count section, omit tag in the summon command, and omit the slash in the summon command:
/setblock ~ ~ ~ minecraft:command_block 11 replace {Command:"summon Item ~ ~ ~ {Item:{id:\"minecraft:iron_ingot\",Count:1b}}"}
Note: This will produce a conditional impulse block facing South.