Json.Decode object with more than 9 property

190 views
Skip to first unread message

Costantino Giuliodori

unread,
Feb 12, 2016, 9:25:03 AM2/12/16
to Elm Discuss
Hello,

How to decode a Json object whit more than 9 properties of different type?
I've an api that get a record of the type:
Json.maybe lias BaseData =                                                          
   { code:           String              
   , acronym:        String             
   , state:          OptGrp.Data       
   , call:           String             
   , title:          String             
   , subject:        OptGrp.Data        
   , theme:          String             
   , euProgram:      OptGrp.Data        
   , ou:             OptGrp.Data        
   , total:          Float             
   , amountRM:       Float       
   , percEUFounding: Float             
   , percState:      Float             
   , percReg:        Float       
   , amountSVIM:     Float             
   , startInt:      Int                
   , endInt:        Int                
   , website:        String             
   , notes:          String             
 }                                                                                                                                                                                                                               

I must use `map` to jump between intermediate decoders until a Decoder BaseData ?


Max Goldstein

unread,
Feb 12, 2016, 9:31:29 AM2/12/16
to Elm Discuss
See No Red Ink's answer to this problem. Note that it requires a third-party library, which you can get with

elm package install circuithub/elm-json-extra

Costantino Giuliodori

unread,
Feb 12, 2016, 12:49:56 PM2/12/16
to elm-d...@googlegroups.com
thanks Max, the link was really useful.


2016-02-12 15:31 GMT+01:00 Max Goldstein <maxgol...@gmail.com>:
See No Red Ink's answer to this problem. Note that it requires a third-party library, which you can get with

elm package install circuithub/elm-json-extra

--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/YriEKaq6cGg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Costantino Giuliodori

Vitor Capela

unread,
Feb 12, 2016, 5:52:00 PM2/12/16
to elm-d...@googlegroups.com

Shameless plug, but I've written about this in the past. It might be useful, even with the elm-json-extra: http://www.troikatech.com/blog/2015/08/17/decoding-larger-json-objects-in-elm/


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 elm-discuss...@googlegroups.com.

Costantino Giuliodori

unread,
Feb 13, 2016, 7:11:15 AM2/13/16
to elm-d...@googlegroups.com
Your post cleared me on the magic behind (|:) and that my initial hypothesis to do jumps between intermediate decoders
was strange only for my head not yet accustomed to functional languages and the applicative functor things.
As you write, there’s (usually) no magic. I use to say that things too magical smell.
Really helpful.
Reply all
Reply to author
Forward
0 new messages