Thank you both for your help. Leroy, your gist is exactly what I wanted.
Thanks again.
On Fri, Dec 2, 2016 at 7:45 PM Leroy Campbell <artison...@gmail.com> wrote:

> I've posted a full example here:
>
> https://gist.github.com/artisonian/4f62ee4572a788d5d801c997e5a560ce
>
> If it'd be helpful, I can work on a writeup to explain my design choices.
>
> On Friday, December 2, 2016 at 8:11:45 PM UTC-5, Nima Birgani wrote:
>
> 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" : "someem...@sd.cs"
>         "id": "dsd33-wdsds"
>       },
>       {
>         "name": "name 2"
>         "email" : "anot...@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" : "anot...@sd.cs"
>           "id": "0000-wdsds"
>         }
>       },
>       {
>         "accountId": "id 2"
>         "accountName" : "acc name 2"
>         "owner": {
>           "name": "name 1"
>           "email" : "s...@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,
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Elm Discuss" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/elm-discuss/9uL8cqKNL9g/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to