Injected Commas and Colons

Injected Commas and Colons

ljr1981ljr1981 Posts: 22Questions: 4Answers: 0

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

  • kthorngrenkthorngren Posts: 20,300Questions: 26Answers: 4,769
    Answer ✓

    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

  • ljr1981ljr1981 Posts: 22Questions: 4Answers: 0

    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:

    action:edit
    data[x123][key]:x123
    data[x123][name]:x223
    data[x123][spec]:A,B
    data[x123][uom]:x
    data[x123][cubic_feet]:1
    data[x123][cost_per_hour]:2
    data[x123][cost_fixed]:3
    data[x123][cost_to_purchase]:4
    

    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! :smile:

  • ljr1981ljr1981 Posts: 22Questions: 4Answers: 0

    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.

This discussion has been closed.