Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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";}}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading