Minecraft new 1.14.2 tag display name detection command [duplicate]

I am in 1.13 Pre-Release 7 trying to make a one command creation and I need an item with a specific name. The command I use is /give @p diamond_sword{display:{Name:"Sword of Power"}} and it gives my a diamond sword, but it doesn't have the name.

This is me trying the command This is me running the command.

This is the command not working This is the command not working.


Solution 1:

In 1.13 many things are JSON that were previously just simple strings. So the syntax is now:

give @p diamond_sword{display:{Name:"{\"text\":\"Sword of Power\"}"}}

This also means that you can colour the text, make it underlined, translatable, obfuscated, etc.

With Minecraft 1.14, support for single-quoted strings has now been added. This means that you can shorten JSON strings by surrounding them in single quotes ' instead of double quotes:

give @p diamond_sword{display:{Name:'{"text":"Sword of Power"}'}}

Whenever an NBT check doesn't work like you expected, I always recommend /data get. For example in this case you can hold the item and run:

/data get entity @s SelectedItem

Solution 2:

In 1.14 and above, putting JSON text components into NBT string tags has been made a lot easier. Instead of having to escape every " with a \, surround the entire NBT tag string with single quotes ' instead of double quotes ". This means you can freely include double quotes in your string without having to escape them. This will mean that you will need to escape every single quote though, but there will not be that many single quotes in your JSON text component unless you explicitly need them.

Note that a single-quoted string with the same text as a double quoted string count as aliases and are equivalent to each other. Single quoted strings are now the default for all NBT string tags that involve JSON text elements. This is evident because using /data get will show the Name tag as a single-quoted string, no matter whether it was set using a single or double quoted string.

Here is the 1.14 way to give yourself that sword:

/give @p diamond_sword{display:{Name:'{"text":"Sword of Power"}'}}

Notice the use of single quotes to surround the string in Name instead of using double quotes. This will make creating JSON text in NBT much easier!