This has to do more with showing your faith before men because men can't see your faith so they see your works to known that your justified. Keep in mind they were talking to believers in this letter not nonbelievers. And what about the countless numbers of scriptures that proves that you are saved by grace and by faith.And without actually seeking and doing God's will, you will not be saved.
And brought them out, and said, Sirs, what must I do to be saved?
And they said, Believe on the Lord Jesus Christ, and thou shalt be saved, and thy house.
For by grace are ye saved through faith; and that not of yourselves: it is the gift of God: not of works, lest any man should boast” is a verse from the Bible, Ephesians 2:8–9.
1 John 5:5
"Who is it that overcomes the world? Only the one who believes that Jesus is the Son of God"
John 20:31
"but these are written so that you may believe that Jesus is the Christ, the Son of God, and that by believing you may have life in his name"
1 John 3:23
"And this is his commandment, that we believe in the name of his Son Jesus Christ and love one another, just as he has commanded us"
Romans 10:9-11
"That if you confess with your mouth, 'Jesus is Lord,' and believe in your heart that God raised him from the dead, you will be saved"
Romans 5:1
"Therefore, since we have been justified through faith, we have peace with God through our Lord Jesus Christ"
If salvation is a gift by grace why do have to work for it? It's funny because you claim this legalism but at the same time your still stating a man has do something in order to be saved or proved he's saved. Sounds like a works based salvation to me. Either salvation is by works or its not there's no inbetween.