Open thebenkahn opened 3 years ago
Note that setting the moodlewssettingraw
parameter to true
also doesn't prevent the escaping.
From what I can tell, the get_report_data
function uses the JSON_PRETTY_PRINT
flag when preparing JSON output with json_encode()
. This is where the escaped newlines (\n
) come from. However, as for the escaped quotes, it seems that data is first JSON encoded by Configurable Reports (via get_report_data()
) and then again by Web Services. The JSON string passed back to Web Services is treated like an ordinary text value and escaped like one.
Note also there appears to be a 3rd element to the issue as well perhaps (or having the same root cause as the escaped quotes possibly). ie. in addition to the escaped newlines and escaped double-quotes there's an extra set of double-quotes surrounding the content of the "data" element, specifically around the array brackets.
(See below, I've used @thebenkahn's example JSON, sans the newlines and escaped double-quotes for clarity of illustration)
"data":"[
{
"firstname": "Bart",
"lastname": "Simpson",
"city": "Springfield"
},
{
"firstname": "Lisa",
"lastname": "Simpson",
"city": "" },
{
"firstname": "Homer",
"lastname": "Simpson",
"city": ""
}
]",
"warnings":""
}
Hello, when using the block_configurable_reports_get_report_data function to access report data in JSON format, the payload contains JSON escape characters that can issues when a client parses the data. If possible it would be great if the data could be cleaned prior to being returned to the client.
Example of JSON downloaded via the front-end export as JSON option:
[{"firstname":"Bart","lastname":"Simpson","city":"Springfield"},{"firstname":"Lisa","lastname":"Simpson","city":""},{"firstname":"Homer","lastname":"Simpson","city":""}]
Same data accessed via the web service:
Thanks!