Reshaping JSON?

Hey everyone, looking for some help.

I have an API call that returns JSON in this format:
{
“2103”: {
“injury_body_part”: null,
“player_id”: “2103”,
“stats_id”: null,
“practice_description”: null,
“sport”: “nfl”,
“age”: 27,
“search_rank”: 9999999,
“birth_state”: null,
“weight”: “285”,
“birth_date”: “1991-04-22”,
“sportradar_id”: “4cd4976e-e230-4935-ad3f-c12876a41350”,
“espn_id”: 17054,
“injury_notes”: null,
“hashtag”: “#CodyBooth-NFL-FA-60”,
“height”: “6’5"”,
“depth_chart_position”: null,
“depth_chart_order”: null,
“rotoworld_id”: null,
“last_name”: “Booth”,
“first_name”: “Cody”,
“fantasy_data_id”: 16426,
“fantasy_positions”: [
“OL”
],
“birth_city”: null,
“high_school”: null,
“team”: null,
“position”: “OT”,
“search_full_name”: “codybooth”,
“full_name”: “Cody Booth”,
“rotowire_id”: 9866,
“gsis_id”: null,
“search_last_name”: “booth”,
“news_updated”: null,
“injury_start_date”: null,
“search_first_name”: “cody”,
“active”: false,
“practice_participation”: null,
“number”: 60,
“birth_country”: null,
“yahoo_id”: 27841,
“status”: “Inactive”,
“college”: “Temple”,
“years_exp”: 1,
“injury_status”: null
},
“6250”: {
“injury_body_part”: null,
“player_id”: “6250”,
“stats_id”: null,
“practice_description”: null,
“sport”: “nfl”,
“age”: null,
“search_rank”: 9999999,
“birth_state”: null,
“weight”: “”,
“birth_date”: null,
“sportradar_id”: “9ff46edb-988f-4c8a-ad56-0502808ca1a6”,
“espn_id”: 3916426,
“injury_notes”: null,
“hashtag”: “#EurndrausBryant-NFL-FA-0”,
“height”: “”,
“depth_chart_position”: null,
“depth_chart_order”: null,
“rotoworld_id”: null,
“last_name”: “Bryant”,
“first_name”: “Eurndraus”,
“fantasy_data_id”: 21183,
“fantasy_positions”: [
“DL”
],
“birth_city”: null,
“high_school”: null,
“team”: null,
“position”: “DT”,
“search_full_name”: “eurndrausbryant”,
“full_name”: “Eurndraus Bryant”,
“rotowire_id”: null,
“gsis_id”: null,
“search_last_name”: “bryant”,
“news_updated”: null,
“injury_start_date”: null,
“search_first_name”: “eurndraus”,
“active”: true,
“practice_participation”: null,
“number”: 0,
“birth_country”: null,
“yahoo_id”: 32538,
“status”: “Inactive”,
“college”: null,
“years_exp”: 0,
“injury_status”: null
},

etc etc…

Unfortunately, when i try to set this up in the API Connector labels each value as it’s own type:

Anyone have a good idea of how to force Bubble to treat the categories correctly?

I’ve tried a bunch of things, the closest i can get is getting everything as raw text and then scraping out the leading ID of each chunk via regex, but then i can’t figure out how to feed that back into the API connector as JSON & have it label things.

HELP! :slight_smile:

This is just a bad way to encode a json. I think that the best thing for you may be to create a plugin or ask API provider to review the JSON payload.

Ugh, yeah I was afraid someone would say that. I (gently) suggested that they do that and got a bit of friction. I don’t want to press too hard and get the API turned off.

How would making a plug-in offer different options to use the API in it’s current structure?

Lol, fwiw I just suggested they change their json structure and got the “it’s unlikely we change, but I’ll pass it to the engineers” response.

Sooo… Guess it’s up to me to find a workaround. If anyone has ideas it’d be greatly appreciated.

Can you give link to API doc?

https://docs.sleeper.app/

Specifically the “player” and “stats” requests. The other ones are shaped correctly.

What do you need to do?
Maybe you can use a mix of the javscript tool with API call data set to TEXT instead of json?

I would like to save in one chunk in the database, then access it by using the :filter function.

So I can strip out the leading numbers to each chunk using regex, but I am not fluent enough in JS really know what to do next.