John signed the confession. He did it in the presence of Danforth. Both of these moves signify he jumped through hoops.
When Danforth is so adamant to do is have the evidence that John Proctor admitted to being a witch. But the truth was that John wasn't and this is what John Proctor clung to. He was being asked to confess to a sin that he didn't commit, and admitting it would be a lie, another sin. The irony here is that choosing not to confess, meant he was hung or killed. Thus, for his good behavior, he was punished. For him, he had commited the crime of adultery earler, and I believe his motivation was to feel that he had paid for or been punished for this sin.
According to Puritan culture, I think he did the right thing because if he was a true believer, he earned heaven. Even if not, he earned retribution for his wrong-doing.
Proctor had gone and tried to get Abigail to tell the truth but that had failed. Ironically, she had told him that he was good. She wants him to marry her and be with her and does not care if Elizabeth is convicted and put to death. She actually seems to want this.
I believe this person before him helps John to eventually recognize even more how precious his wife has been and is and her honesty and goodness have been compromised because of him. When he is expected to sign the paper later on and he realizes that they want to use him to present him to the public. He becomes angry and states that they will not use him.
John recognizes that if he lies he can not show his children how to walk like honest men. He also does not want to be a sell-out to his friends.