dragon age originals
dragon age origin's hair mods
Category:2009 video games
Category:2011 video games
Category:2012 video games
Category:2013 video games
Category:2014 video games
Category:2014 video games
Category:2015 video games
Category:2016 video games
Category:2017 video games
Category:2018 video games
Category:2019 video games
Category:Windows games
Category:MacOS games
Category:AOSHI
Category:Role-playing video games
Category:Fantasy video games
Category:Action role-playing video games
Category:Dragon Age
Category:Science fantasy video games
Category:Single-player video games
Category:Video games developed in the United StatesQ:
What's the best way to deserialize a JSON document in Haskell?
I'm working on a project which requires parsing various JSON documents on the web, and a JSON library is required.
I'd like to use the rather verbose json-text library and the excellent JSON library. So far, it seems like the easiest solution is to use the JSON library from Control.JSON, then install json-text as a dependency.
So, to get the ball rolling, I tried to write a simple program to test out json-text, and JSON.
I defined a type:
data Foo = Foo {
bar :: Int
}
And an instance:
instance FromJSON Foo where
parseJSON (Object obj) = Foo $ fromMaybe (error "Foo should never happen") (obj :: Int)
parseJSON _ = error "Foo should never happen"
Which lets me dump the JSON document:
λ> decodeObject "{
"bar": "1"
}" :: Maybe Foo
Just (Foo {bar = 1})
And of course, I can deserialize it:
λ> decodeObject "{
"bar": "1"
}" :: Foo
Foo {bar = 1}
But I want to use json-text for all my parsing needs. And I want to use the FromJSON instances generated for json-text for that. So I thought I'd try to use the json-text library with a json-text generated instance for Foo, like so:
instance FromJSON Foo where
parseJSON = jsonText (jsonText (__ " be359ba680
Related links:
Commentaires