Last active
December 22, 2015 12:39
-
-
Save cosmo0920/6473986 to your computer and use it in GitHub Desktop.
Lens.Aeson
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
-- Initial Lens-Aeson-test.cabal generated by cabal init. For further | |
-- documentation, see http://haskell.org/cabal/users-guide/ | |
name: Lens-Aeson-test | |
version: 0.1.0.0 | |
-- synopsis: | |
-- description: | |
license: MIT | |
license-file: LICENSE | |
author: cosmo0920 | |
-- maintainer: | |
-- copyright: | |
category: Text | |
build-type: Simple | |
cabal-version: >=1.8 | |
executable Lens-Aeson-test | |
main-is: Main.hs | |
-- other-modules: | |
build-depends: base >= 4.5 && < 5 | |
, aeson >= 0.6 | |
, lens >= 3.9 && < 4 | |
, lens-aeson >= 0.1 | |
extensions: OverloadedStrings | |
ExtendedDefaultRules | |
NoImplicitPrelude | |
CPP | |
GADTs |
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 Data.Aeson (decode, Value) | |
import Data.Maybe | |
import Prelude | |
import Control.Lens | |
import Control.Lens.Aeson | |
main :: IO () | |
main = do | |
fstr <- readFile "test.json" | |
let v = fstr :: String | |
let a = fstr ^? key "a" | |
b = fstr ^? key "b" | |
putStrLn $ unlines [ "a value: " ++ (show $ fromJust a) | |
, "b value: " ++ (show $ fromJust 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
% ./dist/build/Lens-Aeson-test/Lens-Aeson-test | |
a value: Number 1 | |
b value: Number 3 |
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
{"a": 1, "b": 3} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment