A specification abiding implementation of JSON RFC-7159 using alex and happy.
Given an example JSON
file.
{ "foo" : [{"bar": [1,2,true,false, {}]}], "baz": { "woz" : [] } }
The following code will parse the above into aeson
's Value
type (via alex
and happy
).
module Main (main) where
import JSON.Parser (parse)
parseWithJSONTest :: IO ()
parseWithJSONTest =
print =<< parse <$> readFile fileName
to yield
Right (Object (fromList [
("foo", Array [Object (fromList [
("bar",Array [Number 1.0,Number 2.0,Bool True,Bool False,Object (fromList [])])])])
,("baz",Object (fromList [("woz",Array [])
]))
]))
nix-build
nix-shell
nix-build && ./result/bin/example -o index.html && open index.html