Use JSON with the ABL data object model
- Last Updated: December 20, 2023
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
This topic provides a brief overview of JSON.
JavaScript data model
JSON objects and arrays in the ABL are based on the objects and arrays of the JavaScript data model.
JavaScript objects are associative arrays. Object property names can be any Unicode string. Properties and their values can be added, changed, or deleted at runtime. In addition to the properties being added and deleted, the data type of a property can also be changed at runtime.
A JavaScript array is also a type of JavaScript object. In these arrays, the properties are accessed by a numeric index. Each property is referred to as an element. Each element can have its data type changed at runtime. Hence, it supports heterogeneous arrays (arrays with elements that do not all have the same data type).
Features
The ABL JSON object model allows you to:
- Parse JSON strings or read ABL data objects (such as temp-tables and ProDataSets) into a hierarchy of JSON object and JSON array classes
- Update the individual elements (properties) of each object or array in the hierarchy
- Serialize the entire JSON object hierarchy to a variety of JSON string types (memory-resident character strings, files, etc.)
Use cases
The JSON object model provides the flexibility to interact with JSON in a rich internet application (RIA) that you might develop using a services back end. Frameworks such as AJAX contain JavaScript object libraries with full JSON support. A typical use of the API might be as follows:
- The service receives a request containing JSON.
- The JSON is parsed to create a tree of JsonObjects and JsonArrays.
- Based on the content of the generated objects, the application responds to the request, and gathers results.
- These results are used to modify the existing tree or create a new tree of JSON objects.
- The application serializes the resulting tree and sends the serialized JSON back as a response.
- The application deletes the tree(s) of JSON objects.
ABL support for the JavaScript object model
ABL provides various built-in classes that support the JavaScript object model:
- Progress.Json.ObjectModel.ObjectModelParser class provides public methods that parse a JSON string from a variety of sources and builds a corresponding JSON object hierarchy.
- Progress.Json.ObjectModel.JsonObject class encapsulates a single JSON object, which can contain any number of properties(name/value pairs) of various JSON data types, including other JSON objects or arrays. It provides public methods to access and change the object's data in a number of ways.
- Progress.Json.ObjectModel.JsonArray class encapsulates a single JSON array, which can contain any number of elements of various JSON data types, including other JSON objects or arrays. It provides public methods to access and change the array's data in a number of ways.
- Progress.Json.ObjectModel.JsonDataType provides public properties that allow you to identify the JSON data type of a given property or element in a JSON object or array.
For more information on classes supporting JavaScript object model, see Use JSON Objects and Arrays.