Elm Json.Decoder for javascript Array-like objects, of the form:
{length:2, 0:value0, 1:value1}
This is useful for decoding things like
DOM NodeList
s
coming from javascript ports.
jsonPseudoList : Json.Decode.Decoder a -> Json.Decode.Decoder (List a)
Create a decoder for objects of the form:
{"length": Number, "0": Value, "1": Value, ...}
Takes just one argument: the decoder for `Value`
You need to use Json.Decode with this module
>>> import Json.Decode
>>> Json.Decode.decodeString
... (jsonPseudoList Json.Decode.string)
... """{
... "length": 2,
... "0": "hello",
... "1": "world"
... }"""
Ok ["hello", "world"]
The object to decode may contain supplumentary fields, but if a value is missing, the decoder will fail
>>> Json.Decode.decodeString
... (jsonPseudoList Json.Decode.string)
... """{
... "length": 2,
... "0": "hello"
... }"""
Err "Expecting an object with a field named `1` but instead got: {\"0\":\"hello\",\"length\":2}"
Of course, if the length is less then 0, decoding fails
>>> Json.Decode.decodeString
... (jsonPseudoList Json.Decode.string)
... """{
... "length": -1
... }"""
Err "I ran into a `fail` decoder: Expecting a positive value for the `length` field"