1
0
-1

json_input = "{"insp_result":"C","insp_comment":null,"user_id":null}"

jsontostruct vst_stuct, json_input

vst_struct→insp_comment = "Cancelled"

vst_struct→user_id = "SOMEONE"


Structs now looks like this;

[]

  [insp_result] = "C"

  [insp_comment] = "Cancelled"

  [user_id] = "SOMEONE"


structtojson/whitespace json_out, vst_struct

Json now looks like this;

"

 {

  "insp_result" : "C",

  "insp_comment" : null,

  "user_id" : null

}"


What on earth am I missing here?

Knut


  1. Daniel Iseli

    Hi Knut,

    I had a look at this and I agree that the error handling is insufficient here.

    When a scalar value is defined as number jsonDataType but the value cannot be converted to a JSON number then structToJson falls back to the Uniface data type (e.g. string) and a warning is added to $procReturnContext.

    I think that a value tagged as a null jsonDataType should behave in a similar way or at least throw a warning that is visible in $procReturnContext.

    Will investigate.

    Daniel

CommentAdd your comment...

1 answer

  1.  
    2
    1
    0

    Hi Knut,

    null as none type for UNIFACE.

    replace null by "" in json string.

    or add  :

    vst_struct->insp_comment->$tags->jsonDataType= "string"

    vst_struct->user_id->$tags->jsonDataType= "string"

    Cordialy

    Gilles.

    1. Knut Dybendahl

      Hi Gilles,

      I don't follow you... 

      The jsontostruct moves the tags into the struct - and I can assign values to those tags (and those values are visible in the stuct).  Thus, converting the struct to json should retain those said values and push the values to the json string.  No?

      Regards,

      Knut

    2. Hortion GILLES

      Hi Knut,

      The answer is in the documentation (Structs for JSON Data):

      Json value

      Struct Value

      Struct annotation

      nullMember with no value (an empty string). The jsonDataTypeannotation indicates that it represents the nullJSON keyword.jsonDataType=null

      jsonDataType=null can have only one value : null

      Regards,

      Gilles.


    3. Knut Dybendahl

      I guess good ol' Uniface have spoilt me with data type conversions over the years.. 

      so, rather than Uniface throwing an error when I assign a value to a null datatype in the struct - and despite the fact that the struct, when inspecting the struct in the debugger, has a value as assigned, because the struct datatype is null, it's going to export the value as null....?

      Good grief Charlie Brown.....

      I'll stick to $replace - heck of a lot easier to deal with...

      Regards,

      Knut


    4. Hortion GILLES

      OK or change jsonDataType to string

      Variables

      string json_input,json_out
      struct vst_struct
      EndVariables

      json_input = "{%%"insp_result%%":%%"C%%",%%"insp_comment%%":null,%%"user_id%%":null}"

      jsontostruct vst_struct, json_input
      message/info vst_struct->$dbgstring
      vst_struct->insp_comment->$tags->jsonDataType= "string"
      vst_struct->insp_comment = "Cancelled"
      vst_struct->user_id->$tags->jsonDataType= "string"
      vst_struct->user_id = "SOMEONE"
      message/info vst_struct->$dbgstring

      structtojson/whitespace json_out, vst_struct
      message/info json_out

      Regards,

      Gilles.

    CommentAdd your comment...