@DuaneJohnson. I believe the compiler currently looks for ports and makes decoders for them. Then when you call a particular port or sub, the decoder is called under the covers. Something similar could happen for a Json.Decode.auto method, which could infer the type based on the tagger function it is invoked with. But it would probably have to be raised to the level of a language keyword like with `port` so its usage could be controlled enough that the compiler could find it.
@JamesWilson. I like what you're saying there. One slight tweak I'd make is to use a Result instead of Maybe. I'd like to know which field failed to decode in an error message. @RupertSmith. I can think of one other case: decoding the same JSON to two different models. However, I think if you have a lot of custom rules, decoders would have to do. I don't have recursive fields, and I decode optional fields to Maybe. If I have multiple related Maybes, then I usually change my data model to link them together. Some reasonable defaults would fit 95% of my use cases, and I could use decoders for the one-offs. @RileyEynon-Lynch. That's kindof what I was afraid of in the long term... decoders just being ongoing busy work. Coming from other languages, even back-end languages, decoding JSON just isn't a thing. Even on the back-end, I will setup a reflection-based deserializer with general error handling (e.g. Newtonsoft for .NET) and I'm done. The ongoing work is just maintaining the data types, which I must do anyway. The back-end deserializer does take some initial testing to work out the kinks, but that work has an end after which there is no ongoing maintenance. PSA: There is also a code-gen tool to create decoders from example JSON. http://noredink.github.io/json-to-elm/ (A little late to the party because I forgot to subscribe to updates.) On Saturday, October 1, 2016 at 9:36:37 AM UTC-5, Andrew Radford wrote: > > Not sure if it has been mentioned but there is this effort to create > decoders from swagger definitions: > > https://github.com/ahultgren/swagger-elm > > Still a work in progress, but looks promising. > > > >> >> A tool that would really help me right now would be a json-schema-to-elm >> converter. >> >> -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
