Question about parsing JSON

Posted by dpackerSIG on 19-Sep-2018 14:47

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(omParser:ParseFile("/tmp/test2.json"), JsonObject).

2. Gets the JSON Array "Items"

3. Correctly reports the number of items (1)

4. Appears to get item 1 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 attached.

Thanks,

-Dan

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(1). /* This seems to work - doesn't throw an error */
/* My question - how can I get the Owner Name from joObj2? */
{
    "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.........."
        },
        {
            "Name": "Mickey Mouse SF 10/3, 10/12, 1",
            "Total": 84,
            "CurrencyCode": "USD",
            "Country": "US",
            "CountrySubdivision": "US-CA",
            "CreateDate": "2016-12-16T18:09:16.56",
            "SubmitDate": "2016-12-16T18:12:35.213",
            "ProcessingPaymentDate": "2016-12-16T20:41:07.313",
            "PaidDate": "2016-12-16T20:43:11.057",
            "ReceiptsReceived": true,
            "UserDefinedDate": "2016-12-16T00:00:00",
            "LastComment": "",
            "OwnerLoginID": "mickeymouse@disney.com",
            "OwnerName": "Mickey Mouse",
            "ApproverLoginID": null,
            "ApproverName": null,
            "ApprovalStatusName": "Approved",
            "ApprovalStatusCode": "A_APPR",
            "PaymentStatusName": "Paid",
            "PaymentStatusCode": "P_PAID",
            "LastModifiedDate": "2016-12-16T20:43:11.08",
            "PersonalAmount": 0,
            "AmountDueEmployee": 84,
            "AmountDueCompanyCard": 0,
            "TotalClaimedAmount": 84,
            "TotalApprovedAmount": 84,
            "LedgerName": "DEFAULT",
            "PolicyID": "gWjJ2u5MR53dSMyPMVTh0w89G.........",
            "EverSentBack": false,
            "HasException": true,
            "WorkflowActionUrl": "http://www.concursolutions.com/api/v3.0/expense/reports/report/gWtbOH5mNy8OGqc1LWZgkm$sAJX........../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": "D8FAAF3BE44F4D6183CF",
            "URI": "https://www.concursolutions.com/api/v3.0/expense/reports/D8FAAF3BE4.........."
        }
    ],
}

All Replies

Posted by Peter Judge on 20-Sep-2018 08:16

For arrays, use
DO I = 1 to iArrayLength:
 
You can check what the (JSON) type of each array extent is
                arrayVar:GEtType(i)
which returns an
                Progress.Json.ObjectModel.JsonDataType
.
You can use that to get the data for the extent.
If it’s a JSON object, and you know the property names, use
                objectVar:GetCharacter(<prop-name>)
 
You can also check the type of the object’s properties with
                objectVar:GetType(<prop-name>)
 
Alternatively,
objectVar:GetNames()
returns a character array of the names. You can loop over those to get the types/values of the properties in a JSON object.
 
 
 
 
 

This thread is closed