I'm trying to parse recursive JSON data, something like this:
{
"node": "a",
"children": [
{
"node": "b",
"children": [
{
"node": "c",
"children": null
}
]
},
{
"node": "d",
"children": null
}
]
}
Now I want to implement an instance of FromJSON, so that I can decode it into a data structure like this: the following data structure
data Tree = Node { value :: Text, children :: [Tree]} | Nothing
I have no clue how to do this. I have only seen examples on how to derive instances for flat (non-recursive) JSON structures using Aeson.
null
instead of an empty list. Furthermore why do you create a constructorNothing
here? Without thenull
case, this is actually completely the same as non-flat data. – Willem Van OnsemFromJSON
/ToJSON
instances manually. Do you need help with that? (If no, you can also answer your own question, and this is encouraged!) – Petr