How to display JSON objects in repeating groups

The Reddit API is providing me with a JSON with the following structure:

{
“statusCode”: 200,
“body”:“[{“title”:“000”,
“url”:“000”,
“created_utc”:00000,
“author”:“000”},
{“title”:“111”,
“url”:“111”,
“created_utc”:11111,
“author”:“111”}]”
}

I have been attempting to display each object as each row in a repeating group like the following:

I have tested multiple plugins that parse JSON with no success so far. What would be the easiest way to achieve this?

For reference, here is the actual JSON:

{
    "statusCode": 200,
    "body": "[{\"title\": \"STOP USING PYTHON", \"url\": \"https://i.redd.it/yo7dbdorh22b1.jpg\", \"created_utc\": 1685041589.0, \"author\": \"C-O-S-M-O\"}, {\"title\": \"C++ talking to Python\", \"url\": \"https://i.redd.it/40t7alhvlac91.png\", \"created_utc\": 1658135273.0, \"author\": \"b98765\"}, {\"title\": \"javaToPython\", \"url\": \"https://i.redd.it/8hepred9d4jc1.gif\", \"created_utc\": 1708164237.0, \"author\": \"LinearArray\"}, {\"title\": \"Learning Python 2024\", \"url\": \"https://www.reddit.com/r/learnpython/comments/1aoa0l4/learning_python_2024/\", \"created_utc\": 1707664051.0, \"author\": \"Suspicious-Dentist93\"}, {\"title\": \"i use chatgpt to learn python\", \"url\": \"https://www.reddit.com/r/ChatGPT/comments/13xcy1j/i_use_chatgpt_to_learn_python/\", \"created_utc\": 1685611737.0, \"author\": \"Clinnkk_\"}, {\"title\": \"What can I do with python\", \"url\": \"https://www.reddit.com/r/learnpython/comments/18rzb2n/what_can_i_do_with_python/\", \"created_utc\": 1703678993.0, \"author\": \"RPGNUB\"}, {\"title\": \"When is Python NOT a good choice?\", \"url\": \"https://www.reddit.com/r/learnprogramming/comments/17raa5a/when_is_python_not_a_good_choice/\", \"created_utc\": 1699526730.0, \"author\": \"QueerKenpoDork\"}, {\"title\": \"What is the meaning of \\\"python is a script based language\\\"?\", \"url\": \"https://www.reddit.com/r/learnpython/comments/17pr835/what_is_the_meaning_of_python_is_a_script_based/\", \"created_utc\": 1699352526.0, \"author\": \"WhatDelayIndustries\"}, {\"title\": \"pythonIsTheFuture\", \"url\": \"https://i.redd.it/ixe5vqssej4d1.png\", \"created_utc\": 1717499213.0, \"author\": \"utkarsh_aryan\"}, {\"title\": \"sneakyPython\", \"url\": \"https://i.redd.it/yjnh6900ppwc1.jpeg\", \"created_utc\": 1714088450.0, \"author\": \"Oussama_Gourari\"}]"
  }

Is the body an array in the response or a string?

Assuming the body is an array (not a string as in your example) then you shouldn’t need a plugin to do this.

  1. In your API connector settings, ensure it is being processed as a list:

  1. Ensure your action in the API call is set to “data”:

  1. Make the call in your front-end e.g. to house the api request:

  1. Then create a repeating group within that group to reflect the array (the “body”)

  1. Then create your cells and layout as needed within the repeating group:

If it’s a string then you will need to parse it. Maybe you could use a plugin… but you could do that without too using a little hack involving making multiple calls.

First, grab the “body” text from the source… then construct a JSON object and send it back to your own app to a back-end workflow and have it return JSON (I know this might seem odd but it’s well documented on the forum) then you can apply the steps above and simply throw it into a repeating group.

Hope it helps. Welcome to the forum!

1 Like

Hey thank you very much for the detailed answer! Definitely helped a lot :slight_smile:

To answer your question:

Is the body an array in the response or a string?

The body seems to be an Array wrapped in String (as shown in my sample in the original post).

In the API connector settings, I cannot find the “test json call body” as shown in your screenshot:

Since this API is a function that I wrote as a cloud function (AWS Lambda), should I return a JSON with a body that is an Array?

I updated my function and made the body into an array! Seems like it’s working now.

Thanks a lot!

This topic was automatically closed after 70 days. New replies are no longer allowed.