'get the child element value from first array irrespective of parent element name in JSON

I'm getting below response (snippet) from JSON (for detailed json response hit (GET) https://restcountries.com/v3.1/all in postman or browser)

[
    {
        "status": "officially-assigned",
        "unMember": true,
        "currencies": {
            "KES": {
                "name": "Kenyan shilling",
                "symbol": "Sh"
            }
        }
    }
]

I want to fetch currency name in above json in Oracle Visual Builder irrespective of currency abbreviation like "KES" i must get the currency..name value

I have used below code to fetch currency name value but i'm getting blank value

<oj-table scroll-policy="loadMoreOnScroll" class="oj-flex-item oj-sm-12 oj-md-12"
    data="[[$page.variables.getAllListSDP]]"
    columns='[{"headerText":"Currency","field":"currencies","template":"officialCellTemplate2"}]'>
    <template slot="officialCellTemplate2">
      <oj-bind-text value="[[ $current.data..name"]]"></oj-bind-text>
    </template>
  </oj-table>


Solution 1:[1]

With JSONPath, you should be able to use wildcards to find the name of any currency, assuming the JSON structure of the currencies field is what you have shared.

You'll need to import the JSONPath libraries into your project. The text binding will then become something like this;

<oj-bind-text value="[[ $current.data.[*].name]]"></oj-bind-text>

P.S - I have not tested the behavior of JSONPath with OJet components myself, but theoretically this is how it should work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shivam Puri