Question
· Jun 6, 2019

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

Discussion (2)1
Log in or sign up to continue

You have various options, depending on what you want to achieve:

  1. Added a property of type %DynamicObject or %DynamicArray to a persistent class
  2. Store the JSON content in the Document Data Model
  3. Parse a JSON structure as Eduard indicated and generate the corresponding persistent class(es).
  4. I would not advise to use %Document.Object. Use the Document Model instead.

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.