elm-lang/core/2.0.0

NOTE: this package moved to elm/core

NOTE: this package is not compatible with Elm 0.19.1

Json.Encode

Library for turning Elm values into Json values.

Encoding

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
-- }

Primitives

string : String -> Value
int : Int -> Value
float : Float -> Value
bool : Bool -> Value
null : Value

Arrays

list : List Value -> Value
array : Array Value -> Value

Objects

object : List ( String, Value ) -> Value