Article
Neerav Adam Verma · Dec 24, 2020 1m read

Output to JSON - Date Internal Format

There are couple of options to do this.

1. You can extend your class &JSON.Adaptor, it will do it for you with inbuilt logicaldtodisplay methods

2. Create another request class and do your transformations

3. Before calling the json convert to stream methods, transform the object's field with a ZDT.

---------------------------------------------------------------------------------------------------------------------------------------

 

I have an extremely simple example where there is a class with 3 properties

Class NV.Operations.FileOutbound.Data.P1 Extends (%Persistent, %Populate)
{
Property ClaimId As %String;
Property Amount As %Decimal(SCALE = 2);
Property DateReceived As %Date;
}

In my operation I do this to make a json and output.

tObj = ##class(NV.Operations.FileOutbound.Data.P1).%OpenId(pRequest.StringValue)
##class(Ens.Util.JSON).ObjectToJSONStream(tObj,.jsonstream)
..Adapter.PutStream(tObj.ClaimId_".json",jsonstream)

On output I get Date as internal format and wanted to know if there is a quick fix besides creating my own transformations etc. to convert date to human readable or odbc format. 

{
    "ClaimId":"B2100",
    "Amount":"7712.45",
    "DateReceived":"63874"
}

00
1 0 1 110
Log in or sign up to continue

Replies

There are couple of options to do this.

1. You can extend your class &JSON.Adaptor, it will do it for you with inbuilt logicaldtodisplay methods

2. Create another request class and do your transformations

3. Before calling the json convert to stream methods, transform the object's field with a ZDT.