As an adjunct to my previous post. When moving data from a json object into a struct, and where members are missing or null, then the pbRequireAllMembers might also set the elements to null. Maybe this would require a separate property to handle something like this? Of course this would only be useful if we can then test that a struct element is not null.
BTW I note the improvement in the pbRequireAllMembers property in DataFlex 19.1 as highlighted by the sample code below. In DataFlex 19.0 this would trigger error 4529, Invalid Json Object. Expected …... and require the json object to be pre-processed i.e. remove the null members before calling JsonToDataType.
Code:
Procedure Json2Struct
tStudent Student
Boolean bSuccess
Handle hoJson
Get Create (RefClass(cJsonObject)) To hoJson
Get ParseString Of hoJson '{ "name": "George", "details": { "birthday": null, "age": null, "male": true, "scholar": null }, "ratings": [ null ] }' To bSuccess
If (bSuccess) Begin
Set pbRequireAllMembers Of hoJson To False
Get JsonToDataType Of hoJson To student
End
Else Begin
Send ReportParseError Of hoJson
End
Send Destroy Of hoJson
End_Procedure