Table of Contents
The Error
Error: Error parsing JSON: invalid character
What Causes This
JSON in your configuration has invalid syntax: trailing commas, single quotes, unescaped characters, or BOM characters.
How to Fix It
Solution 1: Use jsonencode()
resource "aws_iam_policy" "main" {
policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Action = "s3:GetObject"
Resource = "*"
}]
})
}
Solution 2: Validate JSON
python3 -m json.tool policy.json
jq . policy.json
Solution 3: Remove BOM Characters
sed -i '1s/^\xEF\xBB\xBF//' policy.json
Prevention Tips
- Pin provider versions — avoid surprise breaking changes
- Use CI/CD — catch errors before they hit production
- Test with
terraform plan— always review before applying - Keep Terraform updated — newer versions have better error messages
- Use
terraform validate— catches syntax errors early
Hands-On Courses
- Terraform for Beginners on CopyPasteLearn
- Terraform By Example — practical code examples
- Terraform Cheat Sheet — quick reference for all commands
Related Articles
- Terraform Troubleshooting - Common Errors and Solutions
- Terraform Enabling and Using Debugging
- Debugging with TFLint
Conclusion
This error is common and fixable. Follow the solutions above, and check our Terraform course for hands-on training that covers real-world troubleshooting scenarios.

