Cindiary / elm-not-empty / Json.Decode.NotEmpty

Functions for encoding not empty collections into JSON values

list : Json.Decode.Decoder item -> Json.Decode.Decoder (NotEmpty.List item)

Decode a JSON array into a NotEmpty.List

decodeString ( list int ) "[ 1, 2, 3 ]"   == Ok ( NotEmpty.List.withHead 1 [ 2, 3 ] )
decodeString ( list bool ) "[]"           == Err ...

array : Json.Decode.Decoder item -> Json.Decode.Decoder (NotEmpty.Array item)

Decode a JSON array into a NotEmpty.Array

dict : Json.Decode.Decoder value -> Json.Decode.Decoder (NotEmpty.Dict String value)

Decode a JSON object into a NotEmpty.Dict

import Json.Decode as D
import Json.Decode.NotEmpty exposing(dict)

D.decodeString ( dict D.int ) "{ \"alice\": 42, \"bob\": 99 }" == Ok ( NotEmpty.Dict.fromListWithPair "alice" 42 [ ( "bob", 99 ) ] )

D.decodeString ( dict D.int ) "{}" == Err ...

set : Json.Decode.Decoder comparable -> Json.Decode.Decoder (NotEmpty.Set comparable)

Decode a JSON array into a NotEmpty.Set.Set

string : Json.Decode.Decoder NotEmpty.String

Decode a JSON string into a NotEmpty.String.String