How to check and get json object in WP database?
Question
I need to check if an option value from database is a json object.
This funtion following cannot work :
function isJson( string $str, $is_assoc = true ){
json_decode( $str, $is_assoc );
return (json_last_error() == JSON_ERROR_NONE);
}
It´s normal because with an SQL query I got :
a:2:{i:3;a:4:{s:5:"title";s:0:"";s:4:"text";s:503:"...}}
instead of
{ '3' : { 'title' : "", 'text' : "..." }...}}
How can I do to check if this data is a json object and to get this data as object ?
Final goal : Reaplace correclty value for json object in the database without breaking serialized data.
0
database, json, serialized
3 years
2020-04-07T12:51:47-05:00
2020-04-07T12:51:47-05:00 0 Answers
84 views
0
Leave an answer