I recently tried to get data from a server with an Elm Http module, and I was stuck with json decryption for user types in Elm.
My JSON looks like this:
[{ "id": 1, "name": "John", "address": { "city": "London", "street": "A Street", "id": 1 } }, { "id": 2, "name": "Bob", "address": { "city": "New York", "street": "Another Street", "id": 1 } }]
Which should be decoded:
type alias Person = { id : Int, name: String, address: Address } type alias Address = { id: Int, city: String, street: String }
What I have found so far is that I need to write a decoder function:
personDecoder: Decoder Person personDecoder = object2 Person ("id" := int) ("name" := string)
This is for the first two properties, but how do I integrate the Address attached property and how do I combine it to decode the list?
json elm
rubiktubik
source share