cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Dealing with null hash/nested objects eg Link['webView']['href']

yelah
Deputy Chef I
Deputy Chef I

I have a api call that returns similar to the following json structure:

 

{
    "data": [
        {
            "itemId": "001",
            "links": {
                "self": {
                    "href": "http://website.com/api"
                },
                "webview": {
                    "href": "http://website.com/item"
                }
            }
        },
        {
            "itemId": "002",
            "links": {
                "self": {
                    "href": "http://website.com/api"
                }
                }
            }
        }
    ]
}

 

I would like to save the result in a list and have used the "Create List by Workato" action.
I want to capture the itemId and webView link. To capture the web view link I use the hash formula: Link['webView']['href']

which works but when for example itemId 002 does not have that webView, its null. I get a formula error. 
I have read this article how-to-handle-nulls-2 which is helpful but I am not sure how to implement this with using hash notation as the examples provided where for dot functions or items that are not nested, in forumla mode. 

Any help for this would be great. 

1 ACCEPTED SOLUTION

gary1
Executive Chef III
Executive Chef III

I recently had a similar issue and wasn't able to figure out a way to use the "&" operator with hash notation.

I'd probably just do this and get on with it:

webview.present? ? webview["href"] : nil

 

View solution in original post

2 REPLIES 2

gary1
Executive Chef III
Executive Chef III

I recently had a similar issue and wasn't able to figure out a way to use the "&" operator with hash notation.

I'd probably just do this and get on with it:

webview.present? ? webview["href"] : nil

 

yelah
Deputy Chef I
Deputy Chef I

Thanks that logic works. 

For anyone wanting the notation for checking parent object and returning the nested item as string:

Link['webView'].present? ?  Link['webView']['href'] : nil

below works if you dont mind not getting an object back:

Link['webView'].presence