Search code examples
mysqljsonformatsave

How is this json format saved in my database called?


there is a format that I do not know what it is called, but in my database whenever a json is saved to the database it is done in this format.

How can I convert this format back to Json? Is there an online tool that can do it quickly?

a:3:{s:7:"enabled";s:3:"yes";s:12:"notify_email";s:12:"{site_admin}";s:11:"notify_days";a:1:{i:0;s:3:"Mon";}}

Solution

  • What you have is not JSON, but PHP serialized data. You can convert it back to an associative array using unserialize and then into JSON if required using json_encode:

    $s = 'a:3:{s:7:"enabled";s:3:"yes";s:12:"notify_email";s:12:"{site_admin}";s:11:"notify_days";a:1:{i:0;s:3:"Mon";}}';
    
    $arr = unserialize($s);
    print_r($arr);
    
    echo json_encode($arr);
    

    Output:

    Array
    (
        [enabled] => yes
        [notify_email] => {site_admin}
        [notify_days] => Array
            (
                [0] => Mon
            )
    
    )
    {
        "enabled": "yes",
        "notify_email": "{site_admin}",
        "notify_days": [
            "Mon"
        ]
    }
    

    Demo on 3v4l.org