-
-
Save dawehner/0ddd3d0232c593aea34a3975edee6b9a to your computer and use it in GitHub Desktop.
JSON Decoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"typeID":35, | |
"regionID":10000011, | |
"orders":[ | |
{ | |
"volRemaining":95050881, | |
"volEntered":100000000, | |
"range":32767, | |
"price":3.03, | |
"orderID":4498911653, | |
"minVolume":1, | |
"issueDate":"2016-05-08T14:31:57+00:00", | |
"duration":90, | |
"bid":true | |
}, | |
{ | |
"volRemaining":8953112, | |
"volEntered":8953112, | |
"range":32767, | |
"price":10, | |
"orderID":4588933128, | |
"minVolume":1, | |
"issueDate":"2016-07-11T15:30:37+00:00", | |
"duration":90, | |
"bid":false | |
}, | |
{ | |
"volRemaining":19797893, | |
"volEntered":20000000, | |
"range":0, | |
"price":7.99, | |
"orderID":4594602006, | |
"minVolume":1, | |
"issueDate":"2016-07-20T04:04:42+00:00", | |
"duration":90, | |
"bid":true | |
} | |
], | |
"generatedAt":"2016-07-30T13:52:20+00:00" | |
}, | |
... | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Json.Decode exposing (..) | |
-- Parse above JSON as List Order | |
type alias Order = | |
{ typeID : Int | |
, regionID : Int | |
, generatedAt : String | |
, volRemaining : Int | |
, volEntered : Int | |
, range : Int | |
, price : Float | |
, orderID : Int | |
, minVolume : Int | |
, issueDate : String | |
, duration : Int | |
, bid : Bool | |
} | |
type alias OrderList = List Order | |
type alias Outer = { | |
typeId: Int, | |
regionId: Int, | |
orders: OrderList, | |
} | |
type alias OuterList = List Outer | |
orderDecoder : Decoder (Order) | |
orderDecoder = | |
object8 | |
("volRemaining" := int) | |
-- ... | |
outerDecoder : Decoder (Outer) | |
outerDecoder = | |
object4 Outer | |
("typeId" := int) | |
("regionID" := int) | |
("orders" := list orderDecoder) | |
("generatedAt" := string) | |
outerListDecoder : Decoder (OuterList) | |
outerListDecoder = | |
list outerDecoder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment