Creating Table from Data using Repeat Function

Hi TB Community,

I am currently attempting to figure out a more elegant solution to organizing/parsing data from an API response. The API response is giving comparable rental information

I am wondering if there is a way to create a table which automatically repeats rows for as many comparable properties I receive from that API response. Since sometimes I may get 8 properties, and other times, I may get 11 properties

Here is my current snippet which can get the job done, but isn't dynamic:

Thank you for any help on this!

{urlload: https://zillow-com1.p.rapidapi.com/rentEstimate?address=2094%20W%20104th%20St%2C%20Cleveland%2C%20OH%2044102&d=0.5&propertyType=Apartment&beds=2&baths=1&includeComps=true; done=(res) -> ["response": fromJSON(res)]; headers=x-rapidapi-host:zillow-com1.p.rapidapi.com, x-rapidapi-key:8600c9d200msha72b72532dfcf21p116a52jsnc8845f1db399}

Table:
Address: Beds: Baths: Rent Zestimate: Living Area:

{=address1} {=bedrooms1} {=bathrooms1} {=rentestimate1} {=lvarea1}

{if: address2<>""}{=address2} {=bedrooms2} {=bathrooms2} {=rentestimate2} {=lvarea2}{endif}

{address1=catch((response.comps[1].address), "")}
{bedrooms1=catch((response.comps[1].bedrooms), "")}
{bathrooms1=catch((response.comps[1].bathrooms), "")}
{rentestimate1=catch((response.comps[1].rentZestimate), "")}
{lvarea1=catch((response.comps[1].livingArea), "")}

{address2=catch((response.comps[2].address), "")}
{bedrooms2=catch((response.comps[2].bedrooms), "")}
{bathrooms2=catch((response.comps[2].bathrooms), "")}
{rentestimate2=catch((response.comps[2].rentZestimate), "")}
{lvarea2=catch((response.comps[2].livingArea), "")}

And here is a sample of the raw data that comes from the API Response:

["comparableRentals": 11, "comps": [["bathrooms": 1, "bedrooms": 2, "id": 5, "zpid": "33332647", "longitude": -81.75712, "rentZestimate": 856, "address": "2040 W 103rd St, Cleveland, OH 44102", "distance": 0.112, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": "", "livingArea": 660, "latitude": 41.475826], ["bathrooms": 1, "bedrooms": 2, "id": 40, "zpid": "348994187", "longitude": -81.754585, "rentZestimate": 867, "address": "2006 West Blvd APT 9, Cleveland, OH 44102", "distance": 0.228, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": "", "livingArea": "", "latitude": 41.476376], ["bathrooms": 1, "bedrooms": 2, "id": 8, "zpid": "33332482", "longitude": -81.75809, "rentZestimate": 882, "address": "2086 W 104th St, Cleveland, OH 44102", "distance": 0.013, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": 185300, "livingArea": 700, "latitude": 41.474567], ["bathrooms": 2, "bedrooms": 4, "id": 6, "zpid": "33332341", "longitude": -81.75751, "rentZestimate": 916, "address": "2187 W 104th St, Cleveland, OH 44102", "distance": 0.176, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": 131800, "livingArea": 1770, "latitude": 41.471867], ["bathrooms": 1, "bedrooms": 2, "id": 12, "zpid": "2085210827", "longitude": -81.756035, "rentZestimate": 990, "address": "2136 West Blvd APT 2, Cleveland, OH 44102", "distance": 0.133, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": "", "livingArea": "", "latitude": 41.473217], ["bathrooms": 1, "bedrooms": 2, "id": 13, "zpid": "2086469770", "longitude": -81.756035, "rentZestimate": 990, "address": "2136 West Blvd APT 3, Cleveland, OH 44102", "distance": 0.133, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": "", "livingArea": "", "latitude": 41.473217], ["bathrooms": 1, "bedrooms": 2, "id": 25, "zpid": "349967785", "longitude": -81.75947, "rentZestimate": 1025, "address": "2103 W 106th St #1, Cleveland, OH 44102", "distance": 0.074, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": "", "livingArea": 876, "latitude": 41.474083], ["bathrooms": 1, "bedrooms": 2, "id": 38, "zpid": "33332980", "longitude": -81.75501, "rentZestimate": 1110, "address": "2153 West Blvd, Cleveland, OH 44102", "distance": 0.193, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": 190900, "livingArea": 1000, "latitude": 41.47281], ["bathrooms": 1, "bedrooms": 3, "id": 3, "zpid": "33332450", "longitude": -81.75896, "rentZestimate": 1313, "address": "2142 W 105th St, Cleveland, OH 44102", "distance": 0.101, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": 152900, "livingArea": 1200, "latitude": 41.47307], ["bathrooms": 1, "bedrooms": 4, "id": 30, "zpid": "349967788", "longitude": -81.75947, "rentZestimate": 1317, "address": "2103 W 106th St #2, Cleveland, OH 44102", "distance": 0.074, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": "", "livingArea": 1000, "latitude": 41.474083], ["bathrooms": 2, "bedrooms": 3, "id": 20, "zpid": "33332605", "longitude": -81.75948, "rentZestimate": 1367, "address": "2017 W 106th St, Cleveland, OH 44102", "distance": 0.165, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": 129500, "livingArea": 1994, "latitude": 41.476524]], "skippedRecords": 31, "highRent": 1367, "lowRent": 856, "lat": 41.47438, "median": 990, "long": -81.758087, "percentile_75": 1211.5, "percentile_25": 899]

Hello!

You can achieve this using the {repeat} function and a loop to go through your response data like so:

{repeat: for comp in response["comps"]}
Bathrooms: {=comp["bathrooms"]}
Bedrooms: {=comp["bedrooms"]}
Home type: {=comp["homeType"]}
Address {=comp["address"]}
{endrepeat}

{note}
{response=["comparableRentals": 11, "comps": [["bathrooms": 1, "bedrooms": 2, "id": 5, "zpid": "33332647", "longitude": -81.75712, "rentZestimate": 856, "address": "2040 W 103rd St, Cleveland, OH 44102", "distance": 0.112, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": "", "livingArea": 660, "latitude": 41.475826], ["bathrooms": 1, "bedrooms": 2, "id": 40, "zpid": "348994187", "longitude": -81.754585, "rentZestimate": 867, "address": "2006 West Blvd APT 9, Cleveland, OH 44102", "distance": 0.228, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": "", "livingArea": "", "latitude": 41.476376], ["bathrooms": 1, "bedrooms": 2, "id": 8, "zpid": "33332482", "longitude": -81.75809, "rentZestimate": 882, "address": "2086 W 104th St, Cleveland, OH 44102", "distance": 0.013, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": 185300, "livingArea": 700, "latitude": 41.474567], ["bathrooms": 2, "bedrooms": 4, "id": 6, "zpid": "33332341", "longitude": -81.75751, "rentZestimate": 916, "address": "2187 W 104th St, Cleveland, OH 44102", "distance": 0.176, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": 131800, "livingArea": 1770, "latitude": 41.471867], ["bathrooms": 1, "bedrooms": 2, "id": 12, "zpid": "2085210827", "longitude": -81.756035, "rentZestimate": 990, "address": "2136 West Blvd APT 2, Cleveland, OH 44102", "distance": 0.133, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": "", "livingArea": "", "latitude": 41.473217], ["bathrooms": 1, "bedrooms": 2, "id": 13, "zpid": "2086469770", "longitude": -81.756035, "rentZestimate": 990, "address": "2136 West Blvd APT 3, Cleveland, OH 44102", "distance": 0.133, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": "", "livingArea": "", "latitude": 41.473217], ["bathrooms": 1, "bedrooms": 2, "id": 25, "zpid": "349967785", "longitude": -81.75947, "rentZestimate": 1025, "address": "2103 W 106th St #1, Cleveland, OH 44102", "distance": 0.074, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": "", "livingArea": 876, "latitude": 41.474083], ["bathrooms": 1, "bedrooms": 2, "id": 38, "zpid": "33332980", "longitude": -81.75501, "rentZestimate": 1110, "address": "2153 West Blvd, Cleveland, OH 44102", "distance": 0.193, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": 190900, "livingArea": 1000, "latitude": 41.47281], ["bathrooms": 1, "bedrooms": 3, "id": 3, "zpid": "33332450", "longitude": -81.75896, "rentZestimate": 1313, "address": "2142 W 105th St, Cleveland, OH 44102", "distance": 0.101, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": 152900, "livingArea": 1200, "latitude": 41.47307], ["bathrooms": 1, "bedrooms": 4, "id": 30, "zpid": "349967788", "longitude": -81.75947, "rentZestimate": 1317, "address": "2103 W 106th St #2, Cleveland, OH 44102", "distance": 0.074, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": "", "livingArea": 1000, "latitude": 41.474083], ["bathrooms": 2, "bedrooms": 3, "id": 20, "zpid": "33332605", "longitude": -81.75948, "rentZestimate": 1367, "address": "2017 W 106th St, Cleveland, OH 44102", "distance": 0.165, "homeStatus": "OTHER", "homeType": "APARTMENT", "zestimate": 129500, "livingArea": 1994, "latitude": 41.476524]], "skippedRecords": 31, "highRent": 1367, "lowRent": 856, "lat": 41.47438, "median": 990, "long": -81.758087, "percentile_75": 1211.5, "percentile_25": 899]}
{endnote}

3 Likes

This is perfect- Thank you Obed!!

1 Like