##class(%ZEN.Auxiliary.jsonProvider).%WriteJSONStreamFromObject(), Remove _class property

Primary tabs

I am converting an object to json, but in the result a "_class" property appears, is there any way to remove this?


SKYankee.Planejamento.Operacao.Car is a %SerialObject






You need to specify pFormat parameter, it defaults to aceloqtw, where:

  • 1-9 : indent with this number of spaces (4 is the default with the 'i' format specifier)
  • a - output null arrays/objects
  • b - line break before opening { of objects
  • c - output the Caché-specific "_class" and "_id" properties
  • d - output Caché numeric properties that have value "" as null
  • e - output empty object properties
  • i - indent with 4 spaces unless 't' or 1-9
  • l - output empty lists
  • n - newline (lf)
  • o - output empty arrays/objects
  • q - output numeric values unquoted even when they come from a non-numeric property
  • s - use strict JSON output - NOTE: special care should be taken when sending data to a browser, as using this flag may expose you to cross site scripting (XSS) vulnerabilities if the data is sent inside <script> tags. Zen uses this technique extensively, so this flag should NOT be specified for jsonProviders in Zen pages.
  • t - indent with tab character
  • u - output pre-converted to UTF-8 instead of in native internal format
  • w - Windows-style cr/lf newline

In your case explicitly remove c: aeloqtw. This is quoted from documentation.

Additionally if you want to output json to the current device it would be better to use %WriteJSONFromObject - it has the same arguments, except stream, so there's no extra object and io redirect costs:

$$$TOE(tSC, ##class(%ZEN.Auxiliary.jsonProvider).%WriteJSONFromObject(,Store,,,,"aeloqtw")

You might want to post your problem as a separate question.

Eduard, thank you very much again, with the% WriteJSONFromObject function I was able to solve a performance issue. Using WriteJSONStreamFromObject () was taking 1 minute, with% WriteJSONFromObject going to 3 seconds!

Great to hear that!

If you're interested in performance, upgrading to 2016.2+ would help tremendously with JSON processing due to the addition of dynamic objects.

Furthermore, upgrading to IRIS 2019.1.1 would add %JSON.Adaptor which simplifies JSON (de)serialization of normal objects.