Json.Encode

type Value

JavaScript value

  string : String -> Value

int : Int -> Value
float : Float -> Value
Infinity and NaN are encoded as null

bool : Bool -> Value
null : Value

list : List Value -> Value
array : Array Value -> Value
object : List (String, Value) -> Value

 

encode : Int -> Value -> String
convert a Value into a prettified string
the first argument specifies the amount of indentation in the resulting string

person =
    object
      [ ("name", string "Tom")
      , ("age", int 42)
      ]

compact = encode 0 person
-- {"name":"Tom","age":42}

readable = encode 4 person
-- {
--     "name": "Tom",
--     "age": 42
-- }