I have some Json that I want to generate Java DAOs from, and would like to do that with the Aeson library. I have already done it in Python using the json
module, something like this (snippet/pseudo):
j = json.loads(jsonStr)
def ob(j):
while (len(j) != 0):
k, v = j.popitem()
if type(v) is 'dict':
ob(v) # then do more stuff
elif type(v) is 'list':
arr(v) # then do more stuff
# etc etc
In Aeson it seems I can "load" the json as above like decode "{\"name\":\"Dave\",\"age\":2}" :: Maybe Object
(example from package page) but from there I don't understand what to do, all examples I've seen seem to involve writing data classes, which would defeat the purpose in my case.
I can use fromJust :: Maybe a ->
to get fromList [("age",Number 2.0),("name",String "Dave")] :: Object
, but from there I'm clueless. If it were a Map (which fromList makes it seem like) I'd do keys
then begin traversal as above, but it's not a map.
Thankful for any pointers. Doesn't have to be Aeson I suppose, just seemed like a commonly used library. Thanks.