Dan Packer
Member
I have a question about parsing a complex JSON object - How can I get the text value of a particular record (index?) in a JSON object?
I have code that is reading the file, but how (in the example below) can I get the OwnerName of "Donald Duck" in item 2?
My code (also pasted below) does the following correctly:
1. Convert a file into a JSON object: joJsonObj = CAST(omParserarseFile("/tmp/test2.json"), JsonObject).
2. Gets the JSON Array "Items"
3. Correctly reports the number of items (3)
4. Appears to get item 2 as a JSON Object
5. How do I read a text value OwnerName from the JSON Object in step 4?
Any help would be greatly appreciated. Code and JSON pasted below.
Thanks,
-Dan
I have code that is reading the file, but how (in the example below) can I get the OwnerName of "Donald Duck" in item 2?
My code (also pasted below) does the following correctly:
1. Convert a file into a JSON object: joJsonObj = CAST(omParserarseFile("/tmp/test2.json"), JsonObject).
2. Gets the JSON Array "Items"
3. Correctly reports the number of items (3)
4. Appears to get item 2 as a JSON Object
5. How do I read a text value OwnerName from the JSON Object in step 4?
Any help would be greatly appreciated. Code and JSON pasted below.
Thanks,
-Dan
Code:
USING Progress.Json.ObjectModel.*.
&SCOPED-DEFINE usrwKey "concurReportHeader"
DEFINE VARIABLE omParser AS ObjectModelParser NO-UNDO.
DEFINE VARIABLE jsConstruct AS JsonConstruct NO-UNDO.
DEFINE VARIABLE joJsonObj AS JsonObject NO-UNDO.
DEFINE VARIABLE oJsonArray AS JsonArray.
omParser = NEW ObjectModelParser ( ).
joJsonObj = CAST(omParser:ParseFile("/tmp/test2.json"), JsonObject).
oJsonArray = joJsonObj:GetJsonArray("Items").
MESSAGE oJsonArray:LENGTH. /* ** This works fine, I get a length of 3 ** */
DEFINE VARIABLE OrderInfo AS LONGCHAR NO-UNDO.
def var joObj2 as JsonObject.
DEFINE VARIABLE oTestArray AS JsonArray.
joObj2 = oJsonArray:GetJsonObject(2). /* This seems to work - doesn't throw an error */
/* My question - how can I get the Owner Name from joObj2? */
JSON:
{
"Items": [
{
"Name": "Arizona Advisory Board",
"Total": 4,
"CurrencyCode": "USD",
"Country": "US",
"CountrySubdivision": "US-CA",
"CreateDate": "2016-12-16T16:36:48.477",
"SubmitDate": "2016-12-16T20:54:02.637",
"ProcessingPaymentDate": "2016-12-16T20:54:38.093",
"PaidDate": "2016-12-23T19:10:34.137",
"ReceiptsReceived": true,
"UserDefinedDate": "2016-12-05T00:00:00",
"LastComment": "Testing",
"OwnerLoginID": "MinnieMouse@disney.com",
"OwnerName": "Minnie Mouse",
"ApproverLoginID": null,
"ApproverName": null,
"ApprovalStatusName": "Approved",
"ApprovalStatusCode": "A_APPR",
"PaymentStatusName": "Paid",
"PaymentStatusCode": "P_PAID",
"LastModifiedDate": "2016-12-23T19:10:34.443",
"PersonalAmount": 0,
"AmountDueEmployee": 2,
"AmountDueCompanyCard": 0,
"TotalClaimedAmount": 4,
"TotalApprovedAmount": 4,
"LedgerName": "DEFAULT",
"PolicyID": "gWjJ2u5MR53dSMyPMVTh0w89G.........",
"EverSentBack": true,
"HasException": true,
"WorkflowActionUrl": "http://www.concursolutions.com/api/v3.0/expense/reports/report/gWtbPHpmNy8KOpn4M4Fjbq7OUr........../WorkFlowAction?user=ALL",
"OrgUnit1": null,
"OrgUnit2": null,
"OrgUnit3": null,
"OrgUnit4": null,
"OrgUnit5": null,
"OrgUnit6": null,
"Custom1": null,
"Custom2": null,
"Custom3": {
"Type": "Boolean",
"Value": "N",
"Code": null,
"ListItemID": null
},
"Custom4": null,
"Custom5": null,
"Custom6": null,
"Custom7": null,
"Custom8": null,
"Custom9": null,
"Custom10": null,
"Custom11": null,
"Custom12": null,
"Custom13": null,
"Custom14": null,
"Custom15": {
"Type": "List",
"Value": "United States",
"Code": "US",
"ListItemID": "gWkl$pcW18SglmFtnU$p4Vp1.........."
},
"Custom16": null,
"Custom17": null,
"Custom18": null,
"Custom19": null,
"Custom20": null,
"ID": "445912519B.........",
"URI": "https://www.concursolutions.com/api/v3.0/expense/reports/44591251........."
},
{
"Name": "New York Nov 10 - Nov 11",
"Total": 69,
"CurrencyCode": "USD",
"Country": "US",
"CountrySubdivision": "US-CA",
"CreateDate": "2016-12-16T18:01:48.99",
"SubmitDate": "2016-12-16T18:07:29.557",
"ProcessingPaymentDate": "2016-12-16T20:48:54.277",
"PaidDate": "2016-12-16T21:01:27.137",
"ReceiptsReceived": true,
"UserDefinedDate": "2016-12-16T00:00:00",
"LastComment": "Bunch of meetings",
"OwnerLoginID": "donaldduck@disney.com",
"OwnerName": "Donald Duck",
"ApproverLoginID": null,
"ApproverName": null,
"ApprovalStatusName": "Approved",
"ApprovalStatusCode": "A_APPR",
"PaymentStatusName": "Paid",
"PaymentStatusCode": "P_PAID",
"LastModifiedDate": "2016-12-16T21:01:27.137",
"PersonalAmount": 0,
"AmountDueEmployee": 69,
"AmountDueCompanyCard": 0,
"TotalClaimedAmount": 69,
"TotalApprovedAmount": 69,
"LedgerName": "DEFAULT",
"PolicyID": "gWjJ2u5MR53dSMyPMVTh0w89G.........",
"EverSentBack": false,
"HasException": true,
"WorkflowActionUrl": "http://www.concursolutions.com/api/v3.0/expense/reports/report/gWtbOHZmNy8OGqvPYYKeB9$s$pv3........./WorkFlowAction?user=ALL",
"OrgUnit1": null,
"OrgUnit2": null,
"OrgUnit3": null,
"OrgUnit4": null,
"OrgUnit5": null,
"OrgUnit6": null,
"Custom1": {
"Type": "List",
"Value": "G&A:305 - CEO",
"Code": "27000B-1231459685",
"ListItemID": "gWkl$pcW18Tntjp40xneHY0CyY........."
},
"Custom2": null,
"Custom3": {
"Type": "Boolean",
"Value": "N",
"Code": null,
"ListItemID": null
},
"Custom4": null,
"Custom5": null,
"Custom6": null,
"Custom7": null,
"Custom8": null,
"Custom9": null,
"Custom10": null,
"Custom11": null,
"Custom12": null,
"Custom13": null,
"Custom14": null,
"Custom15": {
"Type": "List",
"Value": "United States",
"Code": "US",
"ListItemID": "gWkl$pcW18SglmFtnU$p4Vp1bpC........."
},
"Custom16": null,
"Custom17": null,
"Custom18": null,
"Custom19": null,
"Custom20": null,
"ID": "BD0F522C8A..........",
"URI": "https://www.concursolutions.com/api/v3.0/expense/reports/BD0F522C8A.........."
}
],
}