Resolve PHP json decode error

From LemonWiki共筆
Jump to navigation Jump to search

Syntax error, malformed JSON

Possible causes

  • the input is empty entirely or multiple white spaces
  • the input contains Byte order mark (BOM)[1]
  • Use ' instead of " for quotation

Solution:

Unexpected control character found

Possible causes

Solution:

  • Remove control character. Using PHP:
$replacement = '';
preg_replace('/[\x00-\x1F]/', $replacement, $input);

References

Relates articles