Skip to content

Instantly share code, notes, and snippets.

@amitaibu
Created September 8, 2015 20:44
Show Gist options
  • Save amitaibu/f741e05a8a9f2cbfc73a to your computer and use it in GitHub Desktop.
Save amitaibu/f741e05a8a9f2cbfc73a to your computer and use it in GitHub Desktop.
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)
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