Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove back slashes from json output in php

Tags:

json

php

api

The code I have used:

$val = json_encode(array("test"=>test1,"test2" =>test,"description" => description));
return $val;

The result im getting

{\"test\":\"test1\",\"test2\":\"test\",\"description\":\"description\"}

I need this to fix api

like image 580
Aparna Avatar asked Nov 27 '22 21:11

Aparna


2 Answers

Try with stripslashes()

echo stripslashes('{\"test\":{\"test1\":{\"test1\":[{\"test2\":\"1\",\"test3\": \"foo\",\"test4\":\"bar\",\"test5\":\"test7\"}]}}}');

stripslashes()

like image 102
Sougata Bose Avatar answered Dec 05 '22 05:12

Sougata Bose


Tried this.

$val = json_encode(array(
  "test"=>'test1',
  "test2" =>'test',
  "description" => 'description'
));

$data = json_decode($val, true, JSON_UNESCAPED_SLASHES);
return $data;

This is the result I received.

enter image description here

like image 36
Khachornchit Songsaen Avatar answered Dec 05 '22 04:12

Khachornchit Songsaen