I've just started working with Elm to do some front-end prototyping using a Rest API I'm working on. In general, the API returns "reasonable" data structures that can be decoded because the keys and value-types are well-known, but several resource types return a data
entry that just has raw json that has no predetermined structure.
Everything I've read so far seems to assume you know the structure of the data you're decoding, whereas in plain js it's relatively easy to loop over the keys and reflect on the types in order to determine how they should be handled at runtime. I'm not seeing a clear path toward handling this kind of data in Elm yet.
E.g.,
{
"name":"foo",
"data": {
"bar": [{"baz":123}, "quux"]
},
...
}
I'd like to know if it is currently possible to parse the value of the data
entry with something akin to
function go(obj)
for key in keys(foo)
if foo[key] is an object
go(foo[k])
else if foo[key] is an array
map(go, foo[k])
...
Specifically:
- Is it currently possible to handle unknown, possibly deeply nested and heterogeneous json data in Elm?
- If so, can you give me the key concept or high level intuition on how the author(s) intended data like this to be decoded?