json writer adding extra slash to the serialized file

By | July 5, 2018

if you are getting the serialize result with extra slash like below

{“uploaded_path”:”C:\\xampp\\htdocs\\myproject\\public\\assets\\uploads\\myimages

This issue normaly occurs when missed the json_decode function in the code

For example Refer the below lines of code

$upload_data = array(‘uploaded_path’ => $destinationPath);
$jsonformat=serialize(json_encode($upload_data));

print_r($jsonformat); // this will output as,

{“uploaded_path”:”C:\\xampp\\htdocs\\myproject\\public\\assets\\uploads\\myimages

To remove the double slashes you can use the below function

dd(json_decode(unserialize($jsonformat)));