emilianobovetti / elm-yajson / Yajson.Stringify

Module for converting Yajson.Json to string. May be useful for debugging purpose.

compact : Yajson.Json -> String

Json to string, no newlines, no spaces.

str : String
str =
    compact <| Array
        [ Object [ ( "name", String "Hugo" ) ]
        , Object [ ( "name", String "Manuel" ) ]
        , Object [ ( "name", String "Eva" ) ]
        ]

str == """[{"name":"Hugo"},{"name":"Manuel"},{"name":"Eva"}]"""

pretty : Yajson.Json -> String

Json to string, with an indentation style close to elm-format's.

str : String
str =
    """[{"name":"Hugo"},{"name":"Manuel"},{"name":"Eva"}]"""
        |> fromString
        |> Result.withDefault Null
        |> pretty

str ==
    """[
        { "name": "Hugo"
        }
    ,
        { "name": "Manuel"
        }
    ,
        { "name": "Eva"
        }
    ]"""