InterSystems FAQ rubric
You can avoid the error by specifying a stream object as the argument of %ToJSON() used when generating a JSON string from a dynamic object.
A code example is below.
InterSystems ObjectScript is a scripting language to operate with data using any data model of InterSystems Data Platform (Objects, Relational, Key-Value, Document, Globals) and to develop business logic for serverside applications on InterSystems Data Platform.