I have read about this and people ask this a bit too often.
lets say u have a input
$_POST['json_txt'] = "{
bar:'value 1',
foo:{
baz:'value 2',
fuz:'value 3'
}
}";
We can validate this input using the php function json_last_error ();
Q 1 = Shouldn't there be another option where we can sanitise this json object?
Q2 = Also is the json_last_error(); the absolute way to correctly validate the input and save it to a db (mysql)?
json_decodereturns null, meaning it's invalid.json_last_error ();only works onphp 5 >=5.3.0eval()(which you shouldn't be doing anyway) the string, and it contains something malicious, it will beeval()ed. PHP actually deserializes the string into a structure (if it can).