I was explaining this to my daughter in quite simplified terms the other day- we evolved to taste sugar and enjoy it because finding a sweet edible plant meant we had a source of energy to help us hunt that day. Pretty useful if you’re a hunter-gatherer.
So we seek out sugar. Now we can get it whenever we want it, in much more massive quantities than we are supposed to be processing. Most of us are addicted. I’m not an exception.
Not sure about the jar portion. But the caramelization process is a bit complicated. It uses free sugars and amino acid to make the brown, caramelized flavour.
Onions are ~9 % carbohydrates with 4 % of that being simple sugars capable of caramelizing. Apparently another 2 % is fibre, leaving ~3 % being more complex carbohydrates I guess? Like cellulose or starches maybe. Those can get broken down at some points, but as far I know, need enzymes to do so.
But back to your question, if the small glasses are showing “sugar” as in sucrose, the onions could have either sucrose maybe? Or individual sugars such as glucose and fructose (the 2 components of sucrose). There’s a number of other single sugars that could make up that 4 % though.