Saw the other day an article with the usage of the %ZEN
package when working with JSON and decided to write an article describing a more modern approach. At some recent point, there was a big switch from using %ZEN.Auxiliary.*
to dedicated JSON classes. This allowed to work with JSONs more organically.
Thus, at this point there are basically 3 main classes to work with JSON:
%Library.DynamicObject
- provides a simple and efficient way to encapsulate and work with standard JSON documents. Also, there is a possibility instead of writing the usual code for creating an instance of a class like
set obj = ##class(%Library.DynamicObject).%New()
it is possible to use the following syntax
set obj = {}
-
%Library.DynamicArray
- provides a simple yet efficient way to encapsulate and work with standard JSON arrays. With arrays you can use the same approach as with objects, meaning that yu can either create an instance of the class
set array = ##class(%DynamicArray).%New()
or you can do it by using brackets []
set array = []
%JSON.Adaptor
is a means for mapping ObjectScript objects (registered, serial or persistent) to JSON text or dynamic entities.