· Jan 28, 2021

Looking for a way to Parse or access a JSON response by tag

I have a business process that I call a class that returns a JSON message.  I was hoping to be able to reference the tag or iterate through the response until I find my value.

// Build the request parameter
set tRequest = ##class(CDSM.MemberAPI.Request).%New()
set tRequest.DateOfBirth = ptDOB 
set tRequest.FirstName = ptFname
set tRequest.LastName = ptLname // Business operation needs to be parameterized
set tSC = ..SendRequestSync("boEISLMemberAPI, tRequest")

Just pasting the value I am interested since the response is 300 values long.


Product version: IRIS 2020.2
Discussion (9)0
Log in or sign up to continue

In Cache product line, you would need to use Dynamic Objects. In order to iterate through a JSON Object, you would need to know its structure. Most likely, it is a nested object so you would have drill down to it.

To read your JSON Object into a DynamicObject, use

Set tDynObject = {}.%FromJSON(yourJSONString).

Here is some reference for Dynamic Objects:

In IRIS Product Line, in addition to Dynamic Objects, you have JSON Adaptors. If your class inherits from %JSON.Adaptor, it can recognize JSON  key/value pairs and you can just assign them to the Properties in your object.

Here is a reference for JSON Adaptors: