Skip to main content

structtojson issue

  • January 2, 2019
  • 6 replies
  • 0 views

Knut Dybendahl
Forum|alt.badge.img

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


6 replies

Forum|alt.badge.img
  • Participating Frequently
  • January 3, 2019

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


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.


Knut Dybendahl
Forum|alt.badge.img
  • Author
  • Participating Frequently
  • January 3, 2019

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.

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


Forum|alt.badge.img
  • Participating Frequently
  • January 3, 2019

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.

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.



Knut Dybendahl
Forum|alt.badge.img
  • Author
  • Participating Frequently
  • January 3, 2019

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.

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



Forum|alt.badge.img
  • Participating Frequently
  • January 4, 2019

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.

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.


  • Rocketeer
  • January 11, 2019

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


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