Use serialize() instead of json_encode().  Security issues are primarily with unserialize(), which we're not using, and json_encode() causes recursion errors.