What to do if you get a MAXSTRING error in JSON conversion of dynamic objects
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.
USER>set temp=##class(%Stream.TmpCharacter).%New()
USER>set jsonobj={}
USER>set jsonobj.pro1=["a","b","c","d"]
USER>set jsonobj.pro2=["あ","い","う","え"]
USER>do jsonobj.%ToJSON(temp)
USER>write temp.Size
51
USER>write temp.Read()
{"pro1":["a","b","c","d"],"pro2":["あ","い","う","え"]}See also the documentation for details.
Go to the original post written by @Mihoko Iijima
Discussion (1)0
Comments
This is really useful when we working long strings. If we didn't declare any stream object for the temp variable and pass to %ToJSON(temp). In that case, a %Stream.FileCharacter stream is created