joeybright/json-to-elm/1.0.0

JsonToElm

Take any encoded JSON (as a Json.Encode.JsonValue) and decode it into an Elm value.

= JsonInt Int
| JsonFloat Float
| JsonString String
| JsonBool Bool
| JsonList (List JsonValue)
| JsonObject (Dict String JsonValue)
| JsonNull
| JsonUnknown Value

A custom type that represents possible JSON values as an Elm type.

decode : Decoder JsonValue

A decoder for coverting a Json.Encode.JsonValue into a JsonValue.

If you run decode on the following JSON:

{
    "name": "John",
    "age": 10,
    "money": 10.2,
    "isTired": "true",
    "objects": [ "wallet", "phone", "keys" ]
}

You will get the following JsonValue result:

JsonObject
    (Dict.fromList
        [ ( "name", JsonString "John" )
        , ( "age", JsonInt 10 )
        , ( "money", JsonFloat 10.2 )
        , ( "isTired", JsonBool True )
        , ( "object"
          , JsonList
                [ JsonString "wallet"
                , JsonString "phone"
                , JsonString "keys"
                ]
          )
        ]
    )

You can then manipulate the returned Elm type however you'd like in your program!