Published on InterSystems Developer Community (https://community.intersystems.com)

Home > Creating complex JSON objects and accessing elements within

Question
Aaron Bentley · Oct 23, 2018

Creating complex JSON objects and accessing elements within

Hi,

I have been reading the posts and the documentation around JSON support available with 2016.2 (which is my version) and following versions, but haven't found a concrete example of how to design and implement a complex JSON entity object. I'm working on creating a REST client to connect to an external service and working on modeling the request and response objects, but keep running into invalid OREF when trying to access elements. I've tried creating a container class 'request', which extends %Library.DynamicAbstractObject and has properties tag which is a string and body which is another class that extends %Library.DynamicAbstractObject and contains several collections with defined properties.

Here is an example of the JSON I'm hoping to model into a class:

{
    "tag": "post",
    "body": {
        "patient": {
            "site": [{
                    "code": "string",
                    "mrn": "string"
                }
            ],
            "email": ["string"],
            "addresses": [{
                    "line1": "string",
                    "line2": "string",
                    "city": "string",
                    "state": "string",
                    "postalCode": "string"
                }
            ],
            "names": [{
                    "first": "string",
                    "middle": "string",
                    "last": "string",
                    "suffix": "string"
                }
            ]
        }
    }
}
#Object Data Model #REST API #Ensemble

Source URL:https://community.intersystems.com/post/creating-complex-json-objects-and-accessing-elements-within