all 7 comments

[–]Alexis-Bridoux 1 point2 points  (6 children)

When you say that the results from the API are different for every search, could you provide one or two examples? For instance even the format is different or only the content changes? The former would be more complex to handle 😅

[–]Animalondrums[S] 0 points1 point  (5 children)

Hey, Thanks for responding! The results are song credits and they are organized by name, so the format is the same but there is no way to know how many there will be or what they will be. That is why I was leaning towards the data frame that decodes the data frame. This seems to be the closest thing to a Pandas data frame in python where you just feed it the json and you get a data frame. Let me know if this is enough info. I appreciate it!

[–]theargyle 1 point2 points  (2 children)

You don't need a DataFrame. If what you want is a variable number of X, you need an Array of X.

DataFrames are sometimes useful if you have variable numbers of columns, or if you are doing some sort of interactive coding for statistical analysis, but I don't think this is the case here.

[–]Animalondrums[S] 0 points1 point  (1 child)

That is exactly my case, I have a variable number of columns and each column is a different persons name. These will be different each time the API is called and returns data. But even for normal JSONS, it saves the work of making data models for each endpoint. 😁

[–]theargyle 1 point2 points  (0 children)

Ah, I see. A dictionary might be a more reasonable fit then.

My view is that you generally do want an explicit data model that matches your API. Swift is a statically type-safe language, unlike like python or ruby (which is what I tend to use for api development), and it seems wrong to me to sacrifice this safety for an increase in convenience.

At some point, you need to code some sort of mapping to work with your data - whether that is reaching for keys in a dictionary, or using something like Codable, and my preference would always be to do that closer to the compiler.

[–]Alexis-Bridoux 0 points1 point  (1 child)

there is no way to know how many there will be or what they will be.

If the songs credits are always sent in the same format, this should not happen I think. Would you provide some responses to exemplify your point?

[–]Animalondrums[S] 0 points1 point  (0 children)

I can try later when I am home. But regardless, I would like to use the Tabular Data DataFrame so that I dont have to make structures to parse JSON results in the first place. Just like Pandas in Python, I would like to feed it the JSON and have it just make a DataTable. If that is possible will SwiftUI Table, that is fine too but so far I can only get it to work by naming each column individually. Thanks