This psalm has a thanksgiving song (Psalm 40:1–10) and a lament (40:11–17). The thanksgiving song explains why the psalmist is thankful (Psalm 40:1–5), shows a promise to stay committed (40:6–8), and shares a public testimony about God's character (40:7–10). The lament talks about the psalmist's troubles due to his sins (Psalm 40:11–12) and includes two prayers asking for justice (40:13–15, 17).