How can I create a JSON with the object ID by using the %Object:$toJSON API?
I have the following piece of code bellow where I create an object reference, create a %Object instance from %fromObject and them I am creating the JSON from $toJSON, but it does not expose the %ID (object id). How is the best approach to create a JSON with the respectives object IDs?
Try { Set tPersonObj = ##class(Data.Person).%OpenId(pId) If $Get(%objlasterror) $$$ThrowStatus(%objlasterror) Set tObj = ##class(%Object).$fromObject(tPersonObj) Write tObj.$toJSON() } Catch ex { Set tSC = ex.Status }
The outcome is:
Write tObj.$toJSON() {"Age":28,"MaritalStatus":"Casada","Name":"Emilia de Souza","Sex":"F"}
I am expecting this:
{"ID":5,"Age":28,"MaritalStatus":"Casada","Name":"Emilia de Souza","Sex":"F"}
Thanks.
</body></html>