You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

OIC: Manage response payload having empty key-name

Hi All,

I'm trying to integrate data from an API call.
The reguresponse payload looks like:

"response": {
      "goals": {    
           "for": {  
           "minute": {
                "0-15": {
                    "total": null,
                    "percentage": null
                },
                "16-30": {
                    "total": null,
                    "percentage": null
                },
                "31-45": {
                    "total": 3,
                    "percentage": "21.43%"
                },
                "46-60": {
                    "total": 3,
                    "percentage": "21.43%"
                },
                "61-75": {
                    "total": 1,
                    "percentage": "7.14%"
                },
                "76-90": {
                    "total": null,
                    "percentage": null
                }
            }
        }
}


But sometimes there is an additional key with an empty name ("") and the payload looks like:

"response": {
"goals": {
"for": { "minute": { "0-15": { "total": null, "percentage": null }, "16-30": { "total": null, "percentage": null }, "31-45": { "total": 3, "percentage": "21.43%" }, "46-60": { "total": 3, "percentage": "21.43%" }, "61-75": { "total": 1, "percentage": "7.14%" }, "76-90": { "total": null, "percentage": null }, "": { "total": 5, "percentage": "35.71%" } } } }


I want to check if the incoming response has an element with empty name and then map "total" and "percentage" attributes to the right target.

Tagged:

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!