Parsing JSON objects - Can Dynamic Objects be saved in persistent classes?
Hello,
I want to parse large JSON object and store data into persistent tables. Is there any other way besides pre-defining persistent classes including typing each property name? Maybe parse it and store properties into a global so that I know what properties need to be defined for each class...
Thanks in advance for your thoughts
Check this article on iterating dynamic object.
Instead of just displaying the fields you can use %Dictionary package to generate corresponding class.
After that use new %JSON.Adaptor class (or old %ZEN.Auxiliary.jsonProvider class) to parse JSON into objects.
You have various options, depending on what you want to achieve:
With option 1) and 2) you don't need to define a schema at all, but can easily persist and manage your JSON content as objects. No SQL access to individual properties of the JSON content for option 1). With the document data model you can add support for SQL queries for individual JSON paths.
Option 3) is work, but doable. Figuring out the correct datatypes will be the greatest challenge. If you have JSON schema instead, your life is much simpler.