Inspired by @Ashok Kumar Thangavel's post on the ideas portal here as well as my own wishes for a solution to this problem, I have come up with a simple way to allow more complete and consistent JSON queries without having to specify every desired field. I have created a class that extends the built-in %JSON.Adaptor class and makes its %JSONExportToString and %JSONExportToStream methods accessible through SQL with just a couple of simple SqlProc Methods.
Class DH.JSONAdaptor Extends %JSON.Adaptor [ Abstract ]
{
ClassMethod jsonstring(id, map = "") [ SqlProc ]
{
try{
set myobj = ..%OpenId(id)
set sc = myobj.%JSONExportToString(.json,map)
if $$$ISERR(sc) $$$ThrowStatus(sc)
return json
}
catch ex{
throw ex
}
}
ClassMethod jsonstream(id, map = "") [ SqlProc ]
{
try{
set myobj = ..%OpenId(id)
set sc = myobj.%JSONExportToStream(.json,map)
if $$$ISERR(sc) $$$ThrowStatus(sc)
return json
}
catch ex{
throw ex
}
}
}
.jpg)
(1).jpg)




.png)


