Parsing Json Array

My API returns JSON array which has 3 rows of data with nested fields and sub fields. When i drag to a table, its shows as in screenshot below. However when i try to parse and access just one field , it says 0 rows returned.

{{ GetAccounts.data[0].securitiesAccount.accountId}} Though the auto complete is green and resolves correctly. Is there a specific syntax to loop thru the array like data[i] etc ?

You should probably build a transformer, potentially combined with some array flattening from lodash (built-in to Retool already).

Can't help you much more without know your data schema :-).

@jonathanbredo thanks for your response. the data schema is below. also see this screenshot, it does resolve to the value correctly, just cant figure how to make it show on table.

[
{
"securitiesAccount": {
"type": "CASH",
"accountId": "255104889",
"roundTrips": 0,
"isDayTrader": false,
"isClosingOnlyRestricted": false,
"initialBalances": {
"accruedInterest": 0,
"cashAvailableForTrading": 0,
"cashAvailableForWithdrawal": 0,
"cashBalance": 0,
"bondValue": 0,
"cashReceipts": 0,
"liquidationValue": 0,
"longOptionMarketValue": 0,
"longStockValue": 0,
"moneyMarketFund": 0,
"mutualFundValue": 0,
"shortOptionMarketValue": 0,
"shortStockValue": 0,
"isInCall": false,
"unsettledCash": 0,
"cashDebitCallValue": 0,
"pendingDeposits": 0,
"accountValue": 0
},
"currentBalances": {
"accruedInterest": 0,
"cashBalance": 0,
"cashReceipts": 0,
"longOptionMarketValue": 0,
"liquidationValue": 0,
"longMarketValue": 0,
"moneyMarketFund": 0,
"savings": 0,
"shortMarketValue": 0,
"pendingDeposits": 0,
"cashAvailableForTrading": 0,
"cashAvailableForWithdrawal": 0,
"cashCall": 0,
"longNonMarginableMarketValue": 0,
"totalCash": 0,
"shortOptionMarketValue": 0,
"mutualFundValue": 0,
"bondValue": 0,
"cashDebitCallValue": 0,
"unsettledCash": 0
},
"projectedBalances": {
"cashAvailableForTrading": 0,
"cashAvailableForWithdrawal": 0
}
}
}
]

Try this as source for your table, which will return only the mentioned field as a list:

{{ GetAccounts.data.map(o => o.securitiesAccount.accountId}}

Or this for all securitiesAccount fields

{{ GetAccounts.data.map(o => o.securitiesAccount}}
1 Like

Hi, I'm 3 hours new to retool.
I've a question and needed your help.

I've this json query result

[
{
"main": {
"cust_num": 2,
"cust_fname": "Jason",
"cust_lname": "Birn",
"cust_addr": "35 Sunset Blvd",
"cust_email": "jbirn@4js.com",
"cust_yts": "2023-04-18 19:43:57",
"cust_rate": 35.9
},
"route": [
{
"cust_num": 2,
"weight": 0,
"shipvia": "FEDEX GROUND"
},
{}
]
},
{
"main": {
"cust_num": 3,
"cust_fname": "Nigel",
"cust_lname": "Kendrick",
"cust_email": "nkendrick@4js.com",
"cust_yts": "2023-04-18 19:43:57",
"cust_rate": 85.2
},
"route": [
{
"cust_num": 3,
"weight": 0,
"shipvia": "USPS"
},
{}
]
},
{
"main": {
"cust_num": 1,
"cust_fname": "Mike",
"cust_lname": "Pilgrim",
"cust_addr": "5 Palms St",
"cust_email": "mpilgrim@4js.com",
"cust_yts": "2023-04-18 19:43:57",
"cust_rate": 45.5
},
"route": [
{
"cust_num": 1,
"weight": 0,
"shipvia": "UPS GROUND"
},
{
"cust_num": 1,
"weight": 75,
"shipvia": "YELLOW FREIGHT"
},
{}
]
}
]

which is nested main and route inside main

I created the table using this and works fine {{ custlist.data.map(o => o.main)}}
I wanted to create a sub table for route for the selected main row

so if I select cust_num:2 for example in the main table, the sub table will show data for route

    "cust_num": 2,
    "weight": 0,
    "shipvia": "FEDEX GROUND"

any help is appreciated deeply

Thanks

Figured it out

{{ custlist.data.map(o => o.route)[ table1.selectedIndex]}}

1 Like