The GetItemEnchants returns a list of lists as you can see in the lore
To do you you repeat For Each in the enchantments variable, lets say the current index value variable is "value", you check If Variable List Contains {value, <the enchantment you want>}, and inside the piston you place a Set Variable: Get List Value {<the variable that will get the level>, value, NUMBER(2)} and then you place a Stop Repeat after the Get List Value to save some cpu
a code of how to do it: (the sword is enchanted but it's not showing in the browser, you can click on Get Give Command and try it)
View DiamondFire Code Templates online.
derpystuff.gitlab.io
You can get the current index of the repeat and do Set List Value and stuff