Getting Invalid JSON error, but jsonlint says it's valid.

Getting Invalid JSON error, but jsonlint says it's valid.

dlanz38dlanz38 Posts: 17Questions: 4Answers: 0

I'm getting the invalid JSON error:
DataTables warning: table id={id} - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

I visited the help link: http://datatables.net/tn/1 and verified the JSON is valid using https://jsonlint.com/ as suggested. To validate, I copied the exact response from the Chrome Console, pasted into jsonlint and hit "Validate JSON" without any modification.

I then decided to hardcode the JSON response by copying it directly from Chrome developer tools, replacing the json_encode($myARR) line (This is PHP). And oddly enough, it works perfectly fine.

I'm thinking there is something like whitespace when my response is dynamically generated (although I've checked this in particular). Has anyone experienced this? What was the cause/fix?

For reference:

Here is the slightly modified JSON. I had to modify some values in order to post. (Note, I validated against JSONLint before modifying anything):

{
    "draw": 1,
    "recordsTotal": 10581,
    "recordsFiltered": 10581,
    "data": [
        ["", "VALUE A", "ZEE100", "20190723", ".1200", "112", "US", "30000", "99999999", "30000", "", "0", ""],
        ["", "VALUE B", "ZEE100", "20190723", ".1420", "112", "US", "30000", "99999999", "30000", "", "0", ""],
        ["", "VALUE C", "ZEE100", "20190416", ".1570", "84", "US", "35000", "99999999", "35000", "", "0", ""],
        ["", "VALUE D", "ZEE100", "20190723", ".0900", "112", "US", "30000", "99999999", "30000", "", "0", ""],
        ["", "VALUE E", "ZEE100", "20190723", ".1350", "112", "US", "30000", "99999999", "30000", "", "0", ""],
        ["", "VALUE F", "ZEE100", "20190723", ".1300", "112", "US", "30000", "99999999", "30000", "", "0", ""],
        ["", "VALUE G", "ZEE100", "20190723", ".1200", "112", "US", "30000", "99999999", "30000", "", "0", ""],
        ["", "VALUE H", "ZEE100", "20190723", ".0960", "112", "US", "30000", "99999999", "30000", "", "0", ""],
        ["", "VALUE I", "ZEE100", "20190723", ".0900", "112", "US", "30000", "99999999", "30000", "", "0", ""],
        ["", "VALUE J", "ZEE100", "20191119", "4322.0000", "98", "US", "16", "99999999", "16", "", "0", ""]
    ]
}

This question has an accepted answers - jump to answer

Answers

  • dlanz38dlanz38 Posts: 17Questions: 4Answers: 0

    Literally figured it out two seconds after posting. The issue was automatic escaping enabled in Twig. I was coping from the "Preview" tab in Chrome developer tools, not the Raw "Response" tab.

    Thank you internet for being my rubber duckie.

  • kthorngrenkthorngren Posts: 21,171Questions: 26Answers: 4,922
    Answer ✓

    Is the above, except for the modified data, from the Response tab of the browser's Network Inspector's Ajax view? If not that is what you should use with https://jsonlint.com/ .

    The Debugger might be a good option to find the problem. If you are worried about the data, only the developers have access to the uploaded debugger image.

    Kevin

This discussion has been closed.