I am creating a webservice in moodle and want to return my std object as a JSON,
public static function add_attendance_lti($attendanceObject)
{
......
$lti_updated = [
'id' => $insert_new_attendance,
'code' => $statusCode,
'message' => $message,
'data' => json_encode($AttendanceLog)
];
return $lti_updated;
}
public static function add_attendance_lti_returns()
{
return new external_single_structure(
array(
'id' => new external_value(PARAM_RAW, 'New Attendance id'),
'code' => new external_value(PARAM_INT, 'status code of response'),
'message' => new external_value(PARAM_TEXT, 'message returned'),
'data' => new external_value(PARAM_RAW, 'Return Value')
)
);
}
Here i am converting the $AttendanceLog std object to JSON using json_encode(), but this returns the following data,
{
"id": null,
"code": 200,
"message": "Attendance Record already exists",
"data": "{\"sessionid\":\"18\",\"timetaken\":1643335205,\"studentid\":\"4\",\"takenby\":\"3\",\"statusset\":\"49,51,52,50\",\"statusid\":\"52\"}"
}
How can i return a normal "data" JSON object without the \"