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

Home > %JSON.Adaptor export to %DynamicObject aka native JSON

Question
Dmitry Maslennikov · Sep 21, 2020

%JSON.Adaptor export to %DynamicObject aka native JSON

Doing a new project with %JSON.Adaptor, unexpectedly realized that %JSON.Adaptor does not support export to native JSON. %JSONExport just outputs directly to the current device, and there are two more methods %JSONExportToString, and %JSONExportToStream.

In conjunction with generating REST from swagger specification, where any generated method accepts as a result %DynamicObject, which is good. 

I have multiple places in my REST where I have to return JSON for an object, but I have to modify the result a bit, just extend it with some other way.

And having this in my code, I don't like, and anyway I'm not able to add some more properties on the object level.

ClassMethod outputObject(kind As %String, object As %JSON.Adaptor) As %String
{
    $$$ThrowOnError(object.%JSONExportToString(.output))
    Quit "{ """ _ kind _ """: " _ output _ "}"
}

 

And one more question, is there any way on how to export id of the object?

#JSON #REST API #InterSystems IRIS

Source URL:https://community.intersystems.com/post/jsonadaptor-export-dynamicobject-aka-native-json