This topic contains 2 replies, has 2 voices, and was last updated by  Casey Coleman 5 years, 1 month ago.

A problem with the Alphasort argument to json.serialize

  • I started using the alphasort=true argument to some calls to json.serialize and noticed some problematic behavior.

    I’m starting with a json string looking something like this excerpt:
    “CreatedUpdatedDateTime”: “2017-04-12T03:25:44Z”,
    “EstimatedBloodLossUnit”: null,
    “PreOpPreperations”: [],
    “Patient”: null,
    “Encounter”: null

    An initial parse of this string yields a Lua table with the corresponding elements like this:

    In a later step where I’m re-serializing this table, calls to json.serialze with alphasort=false return a faithful representation of the original.
    If the call is made with alphasort=true, the following is returned:
    “CreatedUpdatedDateTime”: “2017-04-12T03:25:44Z”,
    “EstimatedBloodLossUnit”: “NULL”,
    “PreOpPreperations”: {},
    “Patient”: “NULL”,
    “Encounter”: “NULL”

    Basically, the originally empty results are now serialized with a string value of “NULL”.

    That looks like a bug you have found – thank you for that Casey. We’ll get that fixed. In the meantime one could use gsub to replace “NULL” with null.

    Sounds good, Eliot.
    I’ll explore that.

You must be logged in to reply to this topic.