In 1.13+, you can hold the item in your hand and type:
/data get entity @s SelectedItem
You can copy this from the output log, if you want to avoid retyping it all.
The corresponding /give
command would be:
/give @s minecraft:enchanted_book{StoredEnchantments:[{lvl:1s,id:"minecraft:protection"}]}
(note how the extra NBT gets automatically placed inside the tag
tag)
In 1.8 to 1.12, you'll need to throw down the item in front of you and then type:
/entitydata @e[type=Item,r=3] {}
In chat you'll see all of the data of the item entity, which includes stuff like its motion and age. For the item itself, look at the tags inside the Item:
compound tag, highlighted in green below:
Alternatively, you can use an external program such as NBTExplorer to open up the world, then your player's inventory, then find the item you want to look at the tags of.