Property defined as null or consisting of sub-properties
Needing to know how to define a property that can either be sent in my response as
"members": null,
or
"members": [
{
"dob": "1905-05-01",
"firstName": "BOB",
"middleName": "T",
"nameSuffix": "",
"genderCode": "M",
"lastName": "COLLINS",
"memberId": "123421741",
"relationship": "Subscriber"
}
],
Not sure if this is possible. Currently defined as
Product version: IRIS 2020.1
Property members As %DynamicObject;
Since the JSON content of 'members' property is a JSON array (aka the ObjectScript class %DynamicArray) and that array contains a list of JSON objects (aka the ObjectScript class %DynamicObject), I assume you don't really want a members array containing less that 1 element to be the null JSON value but instead you want that members value to be an empty array, I.e.
set ObjectScriptObject.members=[ ]
Making this choice would mean ObjectScriptObject.members is always a %Dynamic.Array containing 0 or more elements.
A *property* of a class always contains an ObjectScript value that can be a string, a canonical decimal number, a $DOUBLE(...) IEEE 64-bit floating-point value or an oref. An oref is a reference to a Class type object which includes the %DynamicArray and %DynamicObject classes. The %DynamicArray/Object classes are special in that they can contain zero or more elements where each element can either be a JSON value or an ObjectScript value. Where appropriate, conversions will be performed between JSON values and ObjectScript values.
ObjectScript variables and [MULTIDIMENSIONAL] properties can contain ObjectScript arrays of ObjectScript values. These ObjectScript arrays are hierarchical, or tree like. Internal and leaf elements can have a value or can be undefined. A non-multidimensional property and an ObjectScript valued element in a %DynamicArray/Object object are not hierarchical and not undefined. Non-multidimensional properties and elements that have not been initialized will have the empty string, "", as their value the first time they are accessed.
Is there anything else that needs to be set along with the %DynamicArray? I also tried %DynamicObject as well.
Property members As %DynamicArray; Property relationship As %String; Storage Default
{
<Data name="members">
<Attribute>members</Attribute>
<Structure>node</Structure>
<Subscript>"members"</Subscript>
</Data>
I assume (according to the error message you show) you are trying to import some JSON-formatted data into an IRIS class. In addition I recommend the reading of https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
To achieve this, you must define two IRIS classes:
Furthermore, I assume you have data like this (I shortened your example to keep things simple):
check the examples:
the output should be:
now import those data
If everything goes well, you should get three "OK"s and your data global looks like this
check member sizes:
and the output should be:
I hope this is a good starting point for you...
Thanks for the response Julius. I have used that before when the property came in the JSON consistently in the same format. In this case it can come in as:
"members": null,
or as:
"members": [
{
"dob": "1905-05-01",
"firstName": "BOB",
"middleName": "T",
"nameSuffix": "",
"genderCode": "M",
"lastName": "COLLINS",
"memberId": "123421741",
"relationship": "Subscriber"
}
],
Not sure this way will accommodate the two possible structures.
Both possible structures are considered. Here, I use the examples from my previous posting:
The second example outputs {} only and not {"members":null}, I don't know why. Maybe there is a parameter which control this behavior, please ask WRC.
From the view of data value, you can consider {} and {"members":null} as equal.
Both representation mean, the members property has no value. But, yes, but you can philosophize about it ...
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue