'Find the "bad control character" that json_decode fails on in PHP?

I have a lot of JSON strings that are 25-50Kb each. I convert these to arrays with json_decode() and it works fine almost every time... But now I have ran into problem, since some of these strings seems to have some bad control character inside.

This is a part of my code that tries to decode the JSON strings to an array:

$data_arr = json_decode($json_data, true, 512, JSON_INVALID_UTF8_IGNORED);

if (is_null($data_arr)) {
   die(json_last_error_msg()); // --> JSON: Unexpected control character found 
}

Now I need to find which character that is "unexpected" in order to remove/change that character before I run the json_decode(). Is there a way to find the bad character that generates the error?



Solution 1:[1]

The bearer token is not properly provided.

kindly recheck whether the word 'Bearer' is mentioned twice.see here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ekansh Srivastva