JSON decode unknown number of fields

The other solution works (I think) but it does simply ignore the information encoded in the numbers and assumes that the fields are always decoded in the right order. This will probably be the case but I think strictly speaking the fields in an object are unordered (so the sender or JavaScript or Elm would be free to present them in a different order). In particular, you should check that keys from “10” on are in the right order because they might also come in lexicographic order where “10” is smaller than “2”.

If that is a problem, I would do something like this and use it to write the “boxes” and “items” decoders

decodeStrangeList : Decoder a -> Decoder (List a)
decodeStrangeList sub =
    Decode.dict sub
    |> Decode.andThen
        (\stringDict ->
            stringDict
            |> Dict.foldl
                (\string value mIntDict ->
                    case (String.toInt string, mIntDict) of
                        (Just int, Just intDict) ->
                            Just (Dict.insert int value intDict)
                        _ ->
                            Nothing
                )
                Just Dict.empty
            |> Maybe.map (Dict.values >> Decode.succeed)
            |> Maybe.withDefault (Decode.fail "One of the keys was not an integer")
        )

(I must admit that I did not test this.) This solution will return the elements in the right order. It does not check that every key exists, so if the indices are important, an even more complicated solution would be necessary.