TSFoster/elm-uuid

Idea: Add a JSON decoder

Closed this issue · 2 comments

0scvr commented

I'm using the awesome package you've made in my project to generate unique IDs and it would be really helpful to have a Json.Decode.Decoder UUID that can parse the UUIDs from my backend actual UUIDs rather than just Strings containing a UUID.

Done and published (https://package.elm-lang.org/packages/TSFoster/elm-uuid/4.1.0) 👍. Adds UUID.jsonDecoder, UUID.toValue and UUID.toValueWithRepresentation.

Background: I decided against adding decoder/encoders back in v2 of this package, when fromString was returning Result String UUID, and it could be trivially converted to a decoder with Json.Decode.Extra.fromResult. I also didn't like adding a decoder without a toValue, and I wasn't really sure about whether it was this package's job to assume how the UUID was represented in the user's JSON (e.g. API specs often require UUIDs to be in non-standard formats, such as using capitals for A-F).

0scvr commented

Wow, that was fast! Thanks a lot. I did find it odd that you hadn't thought of adding a JSON decoder; I don't know much about UUIDs though and I wasn't aware of the different formats that exist. I understand you concern now, but I think I guess the decoder can always be changed in the future if different formats need to be supported, right?