Villager trade issue with canplaceon item [duplicate]

The CanPlaceOn list and all other item data is inside the tag compound tag:

{
  Items:[ 
    {
      id: "minecraft:wooden_button",
      Count: 1b,
      Slot: 0b,
      tag:{
        CanPlaceOn:[
          "minecraft:log"
        ]
      }
    }
  ]
}

Example command for 1.12−:

/setblock 294 5 -1251 minecraft:chest 0 replace {Items:[{Count:1b,Slot:0b,id:"minecraft:wooden_button",tag:{CanPlaceOn:["log"]}}]}

Example command for 1.13+:

/setblock 294 5 -1251 minecraft:chest{Items:[{Count:1b,Slot:0b,id:"minecraft:wooden_button",tag:{CanPlaceOn:["minecraft:log"]}}]}

Item NBT structure can be found on this wiki page.

Common mistakes include:

  • forgetting tag:
    {
      id: "minecraft:wooden_button",
      Count: 1b,
      CanPlaceOn: [
        "minecraft:log"
      ]
    }
    
  • attempting to put it inside the item ID:
    {
      id: "minecraft:wooden_button{CanPlaceOn:['minecraft:log']}",
      Count: 1b
    }