The protagonist is usually the "good guy" in a story, but not always. Technically, the protagonist will be the character we root for in a story but more generally the protagonist can be defined simple as the central character.
Many movies use an anti-hero character as the protagonist (Scarface) and some novels do this as well.
In Jack and the Beanstalk, Jack always seemed the hero of the story because he saved the family farm by outwitting the ogre. But, look at it this way . . . Jack made some poor decisions along the way which could have led to disaster. But, he was lucky things turned out as well as they did. His mother sent him to sell the cow and he bought the bean seeds instead. When she found out what he had done, in her anger she threw them out the window. Now those beans were magical beans and they grew into a huge beanstalk that reached out of sight up into the sky. We all know the rest of the story: Jack climbs the beanstalk, outsmarts the ogre, takes all his treasures, climbs back down the beanstalk with the ogre after him, then chops down the beanstalk sending the ogre crashing to his death. But, the question is asked, "Was Jack the protagonist in the story?" Was he justified in what he did? Yes and no. In some versions of the story the ogre had actually preyed on the people down below him, stealing things from them and killing their livestock, and then escaping up the beanstalk to his home. Jack could have been justified in what he did. But two wrongs don't make a right, and stealing is stealing, so my opinion is that Jack was in the wrong and shouldn't be made out to be a hero even though he helped improve his family's financial condition and destroyed a possible villain.