· Dec 9, 2019

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

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


Discussion (6)0
Log in or sign up to continue

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")