Saving Objects from API json reponse

I’m having a really bad week… :laughing:

I have a new API service that I call with a GET request which returns the results for that day, as what they call a file with one JSON string per line, such as:


Although there are over 200 objects.

Previously with I could treat it as a list as it was formatted as an array (within square brackets) so I could iterate over each item in the list and save it to the database.
I can call the API and get the response, and all I want to do is save each of the 200 objects into the database.

But I cant find a way in codeless to differentiate between each object and save it. If I try and add the response to a list it just generates one item.

Could anyone suggest a solution to prevent me loosing the plot please?

I’d try to use a regex block to split the response into a collection of strings, where each item in the collection is a separate JSON object. Then iterate over the collection and convert the JSON string into an object. Then save all the objects in the DB. Here’s a schematic flow of the logic (I haven’t tested it):

1 Like

That’s a great idea, will give it a try, thanks Mark.

with a couple of tweaks this worked a treat. thanks again Mark.

What were the tweaks?

The regex expression only needed to be \n rather than the standard \\r?\\n for a line break. For some reason codeless didn’t like this, and the limit needed to be applied to stop it throwing an error, although it still worked fine without the limit but I had an error in the logs. Through the same API i know how many lines to expect so I just add that as a variable.
I also handled each object individually as bulk create is limited to 100, my files were several hundred objects long.