Home > Software engineering >  Get proper json string laravel
Get proper json string laravel

Time:12-19

How can I remove \ ??

img1

$labType=array();
foreach ($landslide->testingDetailLab as $lab) {
    $labType[]= $lab;        
}
$problemiden =array();
foreach($landslide->problemIdentification as $problem){
    $problemiden[]=($problem);
}
                
$data = [
   "lab_type"=>json_encode($labType),
   "problem_identifiation"=>json_encode($problemiden),
]

Tried to get proper json string ,is there any way to remove / form json string

How can i get it in this format:

img2

CodePudding user response:

I think you are looking for JSON_UNESCAPED_SLASHES flag.

$labType = [];
foreach ($landslide->testingDetailLab as $lab) {
    $labType[] = $lab;
}
$problemiden = [];
foreach ($landslide->problemIdentification as $problem) {
    $problemiden[] = $problem;
}

$data = [
    "lab_type" => json_encode($labType,JSON_UNESCAPED_SLASHES),
    "problem_identifiation" => json_encode($problemiden,JSON_UNESCAPED_SLASHES),
];

CodePudding user response:

I guess you could try something like

json_encode(json_decode($labType))
  • Related