Minecraft Commands – How to Add to NBT Array

minecraft-commandsminecraft-java-edition

I'm having (for example) a entity (Drop) with this NBT:

{Item:{tag:{display:{Lore:["test1"]}},id:"minecraft:bread"}}

I'm trying to add a new lore:

/data merge entity @e[type=item,tag=myDrop] {Item:{tag:{display:{Lore:["test2"]}}}}

But when I execute this and collect my drop there is ONLY test2 as lore but i need test1 and test2.
Please help!
Thanks.

EDIT: I don't know the content and/or the count of test1.

EDIT2: So simply a array.append() but how in minecraft?

Best Answer

1.14 introduces this feature using the "append" mode of /data modify:

/data modify entity @e[type=item,limit=1] Item.tag.display.Lore append value "{\"text\":\"second line\"}"
Related Topic