At first glance, this verse seems to contradict Romans 3:28, “We are made right with God through faith and not by obeying the law.” Deeper investigation, however, shows that the teachings of James and Paul are not at odds. While it is true that our good deeds can never earn salvation, true faith always results in a changed life and good deeds. Paul speaks against those who try to be saved by deeds instead of true faith; James speaks against those who confuse mere intellectual assent with true faith. After all, even demons know who Jesus is, but they don’t obey him. True faith involves a commitment of your whole self to God.
But someone will say [to you then], You [say you] have faith, and I have [good] works. Now you show me your [alleged] faith apart from any [good] works [if you can], and I by [good] works [of obedience] will show you my faith.
James 2:18 AMP
– Life Application Bible