programWithFlags with Dict or alternative

I’d like to use Html.programWithFlags to pass a JS object to Elm. I figured that a Dict type best represents what I’m passing to Elm, but I got across this message when trying to make it work:

Your `main` is demanding an unsupported type as a flag.

The specific unsupported type is:

    Dict String String

The types of values that can flow through in and out of Elm include:

    Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples, Json.Values,
    and concrete records.

Here is the code:

The flags I’m passing is an object with lots of keys, holding translations (strings). Using a Dict would be convenient since I don’t want to list every single field as String in Elm (is this bad practice?).

What’s the best way to solve this? Thanks!

You can get whatever type you want by using a manual JSON Decoder. See this ellie:


You can pass in a List (String, String) and pass that to Dict.fromList before saving to your model.


Awesome, thank you @gampleman @lydell for the solutions!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.