Created
September 8, 2015 20:44
-
-
Save amitaibu/f741e05a8a9f2cbfc73a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Detected errors in 1 module. | |
## ERRORS in src/TestJson.elm ################################################## | |
-- TYPE MISMATCH ---------------------------------------------- src/TestJson.elm | |
The 1st argument to function `object3` has an unexpected type. | |
31|> Json.object3 (,) | |
32| ("id" := number) | |
33| ("label" := Json.string) | |
34| ("companies" := Json.list company) | |
As I infer the type of values flowing through your program, I see a conflict | |
between these two types: | |
a -> b | |
(a, b) | |
This file contains hidden or 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 as Json exposing ((:=)) | |
import Graphics.Element exposing (show) | |
import String | |
seralized : String | |
seralized = | |
""" | |
{\"data\":[{\"id\":3,\"label\":\"demo\",\"mail\":\"[email protected]\",\"companies\":[{\"id\":\"1\",\"label\":\"Lexihouse\",\"created\":\"1419533914\",\"updated\":\"1419533914\",\"logo\":{\"fid\":\"1\",\"uid\":\"1\",\"filename\":\"company1.jpg\",\"uri\":\"private:company1.jpg\",\"filemime\":\"imagejpeg\",\"filesize\":\"3388\",\"status\":\"1\",\"timestamp\":\"1419533914\",\"alt\":null,\"title\":null,\"width\":\"283\",\"height\":\"110\",\"image_styles\":{\"thumbnail\":\"http:dev-hedley.pantheon.iosystemfilesstylesthumbnailprivatecompany1.jpg?itok=CfZEAIN9\",\"medium\":\"http:dev-hedley.pantheon.iosystemfilesstylesmediumprivatecompany1.jpg?itok=wRX9CvmC\",\"large\":\"http:dev-hedley.pantheon.iosystemfilesstyleslargeprivatecompany1.jpg?itok=eDfVYpXr\"}}},{\"id\":\"2\",\"label\":\"Voltex\",\"created\":\"1419533914\",\"updated\":\"1419533914\",\"logo\":{\"fid\":\"2\",\"uid\":\"1\",\"filename\":\"company2.jpg\",\"uri\":\"private:company2.jpg\",\"filemime\":\"imagejpeg\",\"filesize\":\"8922\",\"status\":\"1\",\"timestamp\":\"1419533914\",\"alt\":null,\"title\":null,\"width\":\"283\",\"height\":\"113\",\"image_styles\":{\"thumbnail\":\"http:dev-hedley.pantheon.iosystemfilesstylesthumbnailprivatecompany2.jpg?itok=NNbUX2er\",\"medium\":\"http:dev-hedley.pantheon.iosystemfilesstylesmediumprivatecompany2.jpg?itok=6c69zL6O\",\"large\":\"http:dev-hedley.pantheon.iosystemfilesstyleslargeprivatecompany2.jpg?itok=SETEfWUQ\"}}},{\"id\":\"3\",\"label\":\"Santechi\",\"created\":\"1419533914\",\"updated\":\"1419533914\",\"logo\":{\"fid\":\"3\",\"uid\":\"1\",\"filename\":\"company3.jpg\",\"uri\":\"private:company3.jpg\",\"filemime\":\"imagejpeg\",\"filesize\":\"5335\",\"status\":\"1\",\"timestamp\":\"1419533914\",\"alt\":null,\"title\":null,\"width\":\"283\",\"height\":\"213\",\"image_styles\":{\"thumbnail\":\"http:dev-hedley.pantheon.iosystemfilesstylesthumbnailprivatecompany3.jpg?itok=27mdaVFQ\",\"medium\":\"http:dev-hedley.pantheon.iosystemfilesstylesmediumprivatecompany3.jpg?itok=huIRXBfl\",\"large\":\"http:dev-hedley.pantheon.iosystemfilesstyleslargeprivatecompany3.jpg?itok=Wan3LpFZ\"}}}]}],\"count\":6,\"self\":{\"title\":\"Self\",\"href\":\"http:dev-hedley.pantheon.ioapiv1.0me\"},\"next\":{\"title\":\"Next\",\"href\":\"http:dev-hedley.pantheon.ioapiv1.0me?page=2\"}} | |
""" | |
type alias Company = | |
{ id : Int | |
, label : String | |
} | |
decodeData : Json.Decoder (Int, String, List Company) | |
decodeData = | |
let | |
-- Cast String to Int. | |
number : Json.Decoder Int | |
number = | |
Json.oneOf [ Json.int, Json.customDecoder Json.string String.toInt ] | |
company = | |
Json.object2 Company | |
("id" := number) | |
("label" := Json.string) | |
in | |
Json.at ["data", "0"] | |
<| Json.object3 (,) | |
("id" := number) | |
("label" := Json.string) | |
("companies" := Json.list company) | |
main = | |
show (Json.decodeString decodeData seralized) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment