Resolve PHP json decode error: Difference between revisions
Jump to navigation
Jump to search
m (Text replacement - "Category:Text file processing" to "Category:String manipulation") |
|||
| Line 34: | Line 34: | ||
* [https://www.php.net/manual/en/class.jsonexception.php PHP: JsonException - Manual] (PHP 7.3.0) | * [https://www.php.net/manual/en/class.jsonexception.php PHP: JsonException - Manual] (PHP 7.3.0) | ||
[[Category:Data Science]] [[Category:PHP]] [[Category:Json]] [[Category: | [[Category:Data Science]] [[Category:PHP]] [[Category:Json]] [[Category:String manipulation]] | ||
Latest revision as of 19:32, 9 March 2021
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);