Summon a Villager that exchanges 2 Enchanted Books for a higher levelled one (1.12.2) [duplicate]

I'm trying to create NPCs that allow individuals to upgrade their enchanted books beyond what is normally acquirable in survival mode. Basically the idea is that they can take two enchanted books of the same level and trade them for an enchanted book of the next level up.

(E.g. 2 enchanted books with unbreaking I in exchange for 1 enchanted book with unbreaking II)

The following code is the one I have been using to summon the villagers but there are a few issues that I have encountered.

/summon Villager ~ ~ ~ 
{Offers:
    {Recipes:[
        {maxUses:1000,
            buy:{id:enchanted_book,Count:1,Damage:0,tag:{StoredEnchantments:[{id:34,lvl:1}]}},
            buyB:{id:enchanted_book,Count:1,Damage:0,tag:{StoredEnchantments:[{id:34,lvl:1}]}},
            sell:{id:enchanted_book,Count:1,Damage:0,tag:{StoredEnchantments:[{id:34,lvl:2}]}}
        }
    ]},
Silent:1
}

Firstly, I keep getting the "data tag parsing failed" error when trying to execute this command in chat. I'm assuming this is because it is too long to execute in chat since I do not have this issue when using a command block.

Secondly, after summoning the Villager with the command block, the interface is what I want, accepting two books for one. enter image description here

But when I put in the two unbreaking I books, I do not get the unbreaking II book out. It is as if the game detects the two books I have as different from the ones required by the Villager. enter image description here

Anyone can help me identify what is wrong with my code, or tell me if what I am trying to do is not possible.

Thanks!


The command will not fit into chat, you are correct about that causing your error.

The reason the villager will not accept the books is because you are not specifying data type with the id and lvl. The villager is looking for a books with values that are stored as integers. Enchanted books values are stored as shorts when naturally generated so their values should be followed by s (id:34s).

Here is your command with correct data types:

summon Villager ~ ~ ~ {Offers:{Recipes:[{maxUses:1000,buy:{id:enchanted_book,Count:1,Damage:0,tag:{StoredEnchantments:[{id:34s,lvl:1s}]}},buyB:{id:enchanted_book,Count:1,Damage:0,tag:{StoredEnchantments:[{id:34s,lvl:1s}]}},sell:{id:enchanted_book,Count:1,Damage:0,tag:{StoredEnchantments:[{id:34s,lvl:2s}]}}}]},Silent:1}

Which then accepts the books:
Villager