Created
June 7, 2018 18:41
-
-
Save denisshevchenko/b1257a3fa97f228c3ca9e6ad2cce327f 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
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
module Main where | |
import Data.Aeson | |
import Data.Aeson.Encode.Pretty | |
import Data.Aeson.Types | |
import Data.ByteString as B | |
import qualified Data.ByteString.Lazy.Char8 as LC | |
import GHC.Generics | |
import Data.Text | |
data Root = Root | |
{ coord :: Coord | |
} deriving (Generic, Show) | |
data Coord = Coord | |
{ lon :: Double | |
, lat :: Double | |
} deriving (Generic, Show) | |
instance FromJSON Root | |
instance FromJSON Coord | |
main :: IO () | |
main = do | |
jsonString <- B.readFile "/home/denis/test.json" | |
let result = decodeStrict $ jsonString :: Maybe Root | |
case result of | |
Nothing -> print "error" | |
Just r -> print r | |
{- | |
{ | |
"coord": { | |
"lon":44.51, | |
"lat":40.18 | |
} | |
} | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment