ABL temp-tables and ProDataSets have the ability to serialize their data to a JSON string. Similarly, you can read JSON data into a temp-table or ProDataSet. These features parallel the features for XML serialization of temp-tables and ProDataSets.

Features

The JSON features of temp-tables and ProDataSets allow you to take advantage of their rich relational features while providing a standards-based method for sharing data with other application. These JSON features include the following:

  • Read JSON data to populate an empty temp-table or ProDataSet
  • Read JSON data into temp-tables and ProdataSets that already contain data
  • Write JSON data from a temp-table or ProDataSet to a JSON string, a JsonArray object, or a JsonObject object
  • Write JSON data from the current row in a temp-table buffer to a JSON string or JsonObject object

Unlike the matching XML features, you cannot perform a perfect round-trip of JSON write/reads. If the ABL virtual machine (AVM) parses an incoming JSON string into a dynamic temp-table or ProDataSet that does not already have a schema, the AVM must infer the schema from the data. This process means that you are unlikely to have data objects with identical schema on both sides of a transaction. Meta data, like key fields, is lost in the serialization to and from JSON.

The JSON features are available as attributes and methods on:

  • Temp-table objects
  • Temp-table buffer objects (can act on the entire temp-table or the buffers' current contents)
  • ProDataSet objects
  • JsonObject or JsonArray objects

Use cases

The JSON read and write features are robust and versatile. The following examples demonstrate common use cases that can be solved with the features:

  • Provide interoperability between OpenEdge and another JSON-enabled platform or application
  • Use JSON data as a persistent storage mechanism between ABL sessions
  • Simplify or replace existing ABL code that performs JSON reads and writes on temp-tables, temp-table buffers, and ProDataSets

ABL support

The serialization features are provided by the following methods on buffers, temp-tables, and ProDataSets:

  • READ-JSON( ) method — Reads a JSON string into a temp-table or ProDataSet
  • SERIALIZE-ROW( ) method — Writes the current contents of a buffer to a JSON string
  • WRITE-JSON( ) method — Writes the contents of a temp-table or ProDataSet to a JSON string

ABL also supports the following methods:

  • JsonObject:Read( ) method — Reads the data from a ProDataSet, Temp-table or Temp-table buffer object to generate a JSON Object.
  • JsonArray:Read( ) method — Reads the data from Temp-Table object to generate a JSON Array.

You do not need to be familiar with JSON to use these methods and the associated attributes.

For more detailed information, see Use JSON with ProDataSets, Temp-tables, and Temp-table Buffers.