I am reading data from a json file into a temp-table provided by an external vendor. Some fields on the json file are not included every time. How do I check if a field exists on the json file before I attempt to read it. A simplified version of my code looks as follows
In this case 'additional_info' is not always passed so if I don't check prior to reading it I end up with the following error
Call to Progress.Json.ObjectModel.JsonObject:GetCharacter( ) failed. Property 'additional_info' was not found. (16058)
Code:
USING Progress.Json.ObjectModel.ObjectModelParser.
USING Progress.Json.ObjectModel.JsonArray.
USING Progress.Json.ObjectModel.JsonObject.
DEFINE VARIABLE oParser AS ObjectModelParser NO-UNDO.
DEFINE VARIABLE oavailabilityArray AS JsonArray NO-UNDO.
DEFINE VARIABLE oavailabilityObject AS JsonObject NO-UNDO.
define temp-table ttHAPIavailability like HAPIavailability.
oParser = NEW ObjectModelParser().
oavailabilityObject = CAST(oParser:ParseFile("testfile.json"), JsonObject).
create ttHAPIavailability.
assign
ttHAPIavailability.price = decimal(oavailabilityObject:GetCharacter("price"))
ttHAPIavailability.currency = oavailabilityObject:GetCharacter("currency")
ttHAPIavailability.additional_info = oavailabilityObject:GetCharacter("additional_info").
In this case 'additional_info' is not always passed so if I don't check prior to reading it I end up with the following error
Call to Progress.Json.ObjectModel.JsonObject:GetCharacter( ) failed. Property 'additional_info' was not found. (16058)