How to parse wordpress options json

The comments and answers are correct, it is no JSON but indeed a serialized array. The reason you’re having trouble unserializing it is because of the quotes inside the serialized data. David Walsh wrote a neat article about this. The problem is that you can’t simply go into the database and remove these single quotes because the serialized value keeps track of the number of characters in the string (s:6) so you would also need to update that.

Here’s what David Walsh suggests to get around this issue in the future:

//to safely serialize
$safe_string_to_store = base64_encode( serialize( $multidimensional_array ) );

//to unserialize...
$array_restored_from_db = unserialize( base64_decode( $encoded_serialized_string ) );

Leave a Comment