elm-community/json-extra/2.5.0

NOTE: this package is not compatible with Elm 0.19.1

Json.Encode.Extra

Convenience functions for turning Elm values into Json values.

dict : (comparable -> String) -> (v -> Value) -> Dict comparable v -> Value

Turn a Dict into a JSON object.

import Dict


Dict.fromList [ ( "Sue", 38 ), ( "Tom", 42 ) ]
    |> dict identity int
    |> encode 0
--> """{"Sue":38,"Tom":42}"""
maybe : (a -> Value) -> Maybe a -> Value

Encode a Maybe value. If the value is Nothing it will be encoded as null

import Json.Encode exposing (int, null, encode)


maybe int (Just 50)
--> int 50


maybe int Nothing
--> null