I have back slashes that at messes up my JSON. Here is my script:
$path = "https://api.example.com/datasets/v1/horseman?access_token=[snip]";
$include_path = false;
$opts = array('http' =>
array(
'method' => 'GET',
'header' => 'Content-type: application/json',
)
);
$context = stream_context_create($opts);
$mydata = file_get_contents($path, $include_path, $context);
$response = array(
"data" => $mydata, //i need to do this to dump it into datatables.
);
echo json_encode($response,JSON_UNESCAPED_SLASHES);
For some reason, I am getting back slashes added as here is the output;
"data": "[{\"owner\":\"horseman\",\"id\":\"cl5dibmasdasdadsxt\",\"name\":\"goryu\",\"description\":null,\"created\":\"2022-07-09T06:29:53.907Z\",\"modified\":\"2022-07-24T02:57:37.576Z\",\"features\":75,\"size\":16617,\"bounds\":[137.81081,36.658897,137.8403,36.684357]}...
This was a good read about backslashes. Seems JSON_UNESCAPED_SLASHES
is for forward slashed. I am also hesitant to run str_replace
as I would rather find the problem that a work around.
Here is the contents of $mydata
:
[{"owner":"horseman","id":"cl5dirwerwerwe2ts1id4xt","name":"goryu","description":null,"created":"2022-07-09T06:29:53.907Z","modified":"2022-07-24T02:57:37.576Z","features":75,"size":16617,"bounds":[137.81081,36.658897,137.8403,36.684357]},....