Try OpenEdge Now
skip to main content
Working with JSON
Reading and Serializing JSON to/from ProDataSets and Temp-tables : Writing JSON from a temp-table, temp-table buffer, or a ProDataSet : Minimizing the size of JSON data : Omitting foreign key fields in nested child records
Omitting foreign key fields in nested child records
When working with a nested data relation in a ProDataSet, the fields that define the relationship appear in both the parent record and the child records. Because the child records are contained within the parent record, the foreign key fields in the child records are redundant. The WRITE-JSON( ) method omits these foreign key fields if you:
*Specify the FOREIGN-KEY-HIDDEN option on a DEFINE DATA-RELATION statement
*Specify the foreign-key-hidden argument on the ADD-RELATION( ) method of a Data-relation object
*Set the FOREIGN-KEY-HIDDEN attribute of a Data-relation object to TRUE
In all three cases, you must also specify the NESTED option for the data-relation.
Before using this option, consider carefully whether the consumers of the JSON data will handle the missing key fields appropriately. In ABL, the READ-JSON( ) method automatically populates foreign keys in nested child records with the value in the outer parent record when the foreign key is omitted from the JSON data. Unless you are sure that a non-ABL consumer of the JSON data will do the same, do not use this option in your nested data-relations.
For example, while a Web browser can read the JSON data and populate a JavaScript object, it will create rows in the nested table without the foreign key field.