json_decode syntax error from valid json

json_decode syntax error from valid json

By : user2956913
Date : November 22 2020, 03:03 PM
hope this fix your issue As we found in the comments that there are invisible characters in the string, consider running this bit of code. It should show you each character in the string, it'd ascii value and it's printed version.
There should be a few characters in there which do not print anything; those are the ones preventing you from json_encoding the string. I cannot see why they are in the string, that has something to do with your database and the data you post into it, but at least you'll know where the problem is.
code :
for( $i = 0 ; $i < count($string) ; $i++ ) {
  echo 'pos: ' . $i . ' | ord: ' . ord( $string[$i] ) . ' | char: ' . $string[$i] . '<br />';

Share : facebook icon twitter icon
JSON_decode trashes valid json

JSON_decode trashes valid json

By : Endfinder
Date : March 29 2020, 07:55 AM
Hope that helps You are not able to achieve this because in JSON object key names should not be duplicated.
You have events key duplicating many times. In terms of PHP it is fine but in JSON it is not valid.
json_decode returns syntax error with a valid json

json_decode returns syntax error with a valid json

By : DEllis
Date : March 29 2020, 07:55 AM
I wish this helpful for you I'm trying to decode the following json which I have checked with jsonlint and returns that it is a valid json: , In the var_dump I read
code :
string(187) " [{gatewayId: 5154979870408704, ...
Valid JSON Results in PHP json_decode Throwing A Syntax Error

Valid JSON Results in PHP json_decode Throwing A Syntax Error

By : ashwani_gupt
Date : March 29 2020, 07:55 AM
seems to work fine OK. I wanted to let y'all know what happened. It ain't an answer, but it will be the one I greencheck.
I took off and nuked it from orbit, and now it works.
json_decode: 'Syntax error' for valid JSON from HEREDOC string

json_decode: 'Syntax error' for valid JSON from HEREDOC string

By : user2612627
Date : March 29 2020, 07:55 AM
wish helps you The backslashes are acting as PHP escape sequences, not JSON escape sequences. To prevent PHP escaping, surround your heredoc start token in single quotes:
code :
const JSON_CONFIG = <<<'JSON'
  "patterns": {
    "email": "/[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,}/i",
    "phone": "/(?:(?:\\(?(?:0(?:0|11)\\)?[\\s-]?\\(?|\\+)44\\)?[\\s-]?(?:\\(?0\\)?[\\s-]?)?)|(?:\\(?0))(?:(?:\\d{5}\\)?[\\s-]?\\d{4,5})|(?:\\d{4}\\)?[\\s-]?(?:\\d{5}|\\d{3}[\\s-]?\\d{3}))|(?:\\d{3}\\)?[\\s-]?\\d{3}[\\s-]?\\d{3,4})|(?:\\d{2}\\)?[\\s-]?\\d{4}[\\s-]?\\d{4}))(?:[\\s-]?(?:x|ext\\.?|\\#)\\d{3,4})?/"

echo PHP_EOL;

$config = json_decode(mb_convert_encoding(JSON_CONFIG, "UTF-8"), true); // Tried called trim but it made no difference
echo 'json_last_error_msg() => ' . json_last_error_msg() . PHP_EOL;
echo 'json_last_error() => ' . json_last_error() . PHP_EOL;
Problem with json_decode - Syntax error, malformed JSON

Problem with json_decode - Syntax error, malformed JSON

By : alissajess
Date : March 29 2020, 07:55 AM
wish of those help Using the following code I can see there is a non-printable character at the beginning of the JSON:
code :
$json = '{"tomorrow":"2018-09-15"}';
string(37) ""\ufeff{\"tomorrow\":\"2018-09-15\"}""
function remove_utf8_bom($text){
    $bom = pack('H*','EFBBBF');
    $text = preg_replace("/^$bom/", '', $text);
    return $text;
string(31) ""{\"tomorrow\":\"2018-09-15\"}""
function remove_utf8_bom($text)
    $bom = pack('H*','EFBBBF');
    $text = preg_replace("/^$bom/", '', $text);
    return $text;
$json = remove_utf8_bom('{"tomorrow":"2018-09-15"}');
print_r(json_decode($json, TRUE));
string(31) ""{\"tomorrow\":\"2018-09-15\"}""
    [tomorrow] => 2018-09-15
$json = remove_utf8_bom(json_encode($risposta)); // encode here
//echo json_encode($json); // don't really need this, just a test
var_dump(json_decode($json, TRUE)); // you had $json_encode here
array(1) {
  string(10) "2018-09-15"
Related Posts Related Posts :
  • How to make a sitemap using zend framework 1
  • Laravel: array to Model with relationship tree
  • What is the best way to store multiple checkbox values in the database and work with it later on
  • Why does foreach copy the array when we did not modify it in the loop?
  • Receive Jquery/Ajax Post Request in PHP
  • How to better use the if(!empty()){ //codes} statement
  • PHP error mysql_close() boolean given
  • Move an image file from one server to another using PHP
  • PHP: Encoding non ISO-8859-1 charactrers into utf8
  • Handling MySQL errors in PHP
  • Object orientated mysql num_rows query in one line
  • Remove not closed html elements from end of text
  • Generate random ENUM value [PHP, MySQL]
  • Deleting data from table using jQuery and SQL
  • How to make sure the constructor is executed when I'm trying to reach a static property?
  • Trying to understand arrow next to PHP function
  • Form using external php file to show "Sucess"
  • WooCommerce - new shipping method - how to query individual product weights
  • Common integer representation over variable casting?
  • PHP - Prevent client from tampering the ID of a form
  • unexpected T_PUBLIC error
  • Types of testcases in PHPUnit
  • keeping a LDAP user logged in with PHP session
  • Detect if browser supports WebP format? (server side)
  • real_escape_string not cleaning up entered text
  • E-commerce products filter
  • Why having more than one test method in a file using Laravel raises error?
  • PHP Escaped special characters to html
  • Basic prepared statement not INSERTING
  • PHP combobox not showing in HTML table
  • MySql PHP row request to variable
  • Join two tables with one table has multiple rows matching
  • Looping through users with Instagram API requests is REALLY slow
  • Unable to add 30 days to date within loop
  • Return from mysqli_query() into array
  • php rename() function returns "No such file or directory" error
  • form submit inside navigation menu
  • PHP: reasons to use GET and POST request at the same time?
  • Is break; required after die() php
  • little depth of session in php
  • Authentication Logon page not working using PHP and Oracle on Apache / Windows 2008
  • Magento reindexing error product flat data
  • Laravel 4: Running composer when deploying to Heroku
  • Long Polling or WebSockets
  • How to use mysqli_stmt_bind_param for integers, boolean, etc
  • Determining the content of a link
  • MYSQL and PHP update events?
  • PHP explode all square bracket
  • Transparent hexagon-masked collage using PHP GD
  • Plugins or text do NOT show up on custom wordpress template
  • inserting data into mysqli database
  • Two arguments to closure function laravel
  • UnClear image exported by ffmpeg from mp4 file
  • is the time of computer and localhost same?
  • change custom data- value after ajax post success
  • Can We Restrict PHP Variables to accept only certain type of values
  • csv file is inserting a blank row in the last of other rows into mysql table
  • How to convert special characters in xml using php?
  • Mcrypt are very confusing
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org