Resolve PHP json decode error
Jump to navigation
Jump to search
Syntax error, malformed JSON[edit]
Possible causes
- the input is empty entirely or combination of multiple white spaces
- the input contains Byte order mark (BOM)[1]
- One file was combined with multiple JSON which were separated by return symbol
- Use ' instead of " for quotation
Solution:
- Not allowed empty input
- Remove Byte order mark (BOM)
- Use " for quotation
- Use JSONLint - The JSON Validator to validate the JSON format
Unexpected control character found[edit]
Possible causes
- the input string contains control characters
Solution:
- Remove control character. Using PHP:
$replacement = '';
preg_replace('/[\x00-\x1F]/', $replacement, $input);