Hi all,
I'm trying to decode an relatively large JSON to run my app in elm. here is the how my json looks like:
{
"pageTitle" : "users",
"primaryWidget" : "user"
"primaryWidgetData" : {
"permissions" : ["read", "write"]
"data": [
{
"name": "name 1"
"email" : "some...@sd.cs"
"id": "dsd33-wdsds"
},
{
"name": "name 2"
"email" : "ano...@sd.cs"
"id": "0000-wdsds"
}
]
}
}
alternatively my json can be like:
{
"pageTitle" : "accounts",
"primaryWidget" : "account-manager"
"primaryWidgetData" : {
"accounts": [
{
"accountId": "id 1"
"accountName" : "acc name"
"owner": {
"name": "name 2"
"email" : "ano...@sd.cs"
"id": "0000-wdsds"
}
},
{
"accountId": "id 2"
"accountName" : "acc name 2"
"owner": {
"name": "name 1"
"email" : "so...@sd.cs"
"id": "3343-wdsds"
}
}
]
}
}
when I'm decoding the JSON i would like to load the relevant decoder based on the "primaryWidget" and I'm using pipeline decoder:
manifestDecoder : Decoder Manifest
manifestDecoder =
Json.decode Manifest
|> required "pageTitle" string
|> required "primaryWidget" (string |> andThen primaryWidgetDecoder)
|> required "primaryWidgetDat" now I want to pass the relevant loader here but I have no Idea how. tried to use andThen but no luck
Many thanks for reading and helping.
Cheers,