Injected Commas and Colons
Injected Commas and Colons
Consider a field named "foo" with a value of "v1,v2".
My understanding of JSON is that this will be written as {"foo": "v1,v2"} or perhaps as {"foo", "v1\,v2"}.
Either way--what I am getting sent to me is {foo: v1,v2}, which is malformed JSON (e.g. not well-formed).
I have also tried setting the datatypes of the fields to "text" thinking the code responsible for constructing the JSON will enclose each key in double quotes and each value (if typed as "text").
What other choices might I have?
This question has an accepted answers - jump to answer
Answers
What is generating the JSON string?
That's the code that needs to be reviewed to find out why it is malformed. You won't be able to fix it with Datatables configuration.
Kevin
Hi Kevin,
Your feedback is valuable as usual. Here is what I have discovered and am reminded of by the documentation.
Apparently, Datatables does not send JSON back to the server, but something like:
My receiving code (framework) then parses this correctly into a tabular form. There is a feature of that framework code which then attempts to construct a well-formed JSON string based on data provided in the table.
What I can see is that the issue is NOT with Datatables, but with my server-side-JSON-building code.
I can handle it from here!
Follow-up: It does in fact turn out that my own backend library code was create malformed JSON from the datatables format shown above. On my side, I needed to create a pair of alternate routines:
1. json_representation: STRING -- which produces a strictly "key": "value" pair.
2. json_representation_alt: STRING -- which produces JSON based on detected base datatypes (like string and number), where the result is: "key": "value" for strings and "key": value pairs, where value = numeric data (integers, reals, and doubles).
Again--thanks for the feedback. Once again, it helped squash a bug and raised my confidence in the Datatables framework.