John is faced with several very difficult struggles at the end of the play. First of all, he has been in prison for months, struggling with whether or not he should confess to witchcraft in order to get his life back; if he doesn't he will hang. He knows that confessing will be a lie, and, as he states to Elizabeth, "It's hard to give a lie to dogs." But, if he does lie, at least he'll have his life back. Lying, he feels, fits how he feels about himself more--he feels like a sinner, not "a saint to mount the gibbet" with the likes of Rebecca Nurse. He compares himself to people like her, who have reputations of piety and honesty, and feels himself unworthy to be hanged next to her. So, lying would be more suited to his own viewpoint of himself; part of his struggle is that he feels unworthy of noble actions, and still feels like a sinner not deserving of praise or reverence.
Another struggle that he faces is that of making amends with Elizabeth. When they speak for the last time, he begs her forgiveness. In an incredibly poignant scene, she says it is not hers to give, but for him and God to work out between themselves, and then tells him,
"I have sins of my own to count...it takes a cold wife to prompt lechery."
She feels horrible because she was critical and unkind, which didn't help as John was tempted by Abigail. They forgive each other, are reconciled, and have a moment's view of the love they could share if they both lived. His reconciliation with his wife gives him one more temptation to confess.
However, another issue he must face is the impact that confession will have on his reputation. He knows that his name will be tarnished in the town, and he knows that his children will have to live with the fact that his father lied, confessing to witchcraft. It is hard to "teach them to walk like men in the world" when he himself has broken his integrity.
In the end, after almost confessing, he decides not to. This reveals that at his core, he is truly an honest man filled with courage and integrity. It also reveals that for the first time in the course of the play, he feels like he is a good enough man to die next to "saints" on the gibbet. He remarks on this at the end, stating with wonder, "I do think I see some shred of goodness in John Proctor," and Elizabeth doesn't constrain him, realizing that he has finally forgiven himself and feels up to the task of being a good person. She states, "He have his goodness now; God forbid I take it from him," and he is taken to be hanged, with a clean conscience and confident heart.
I hope that those thoughts helped; good luck!