Skip to content

Instantly share code, notes, and snippets.

@cosmo0920
Last active December 22, 2015 12:39
Show Gist options
  • Save cosmo0920/6473986 to your computer and use it in GitHub Desktop.
Save cosmo0920/6473986 to your computer and use it in GitHub Desktop.
Lens.Aeson
-- 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
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)]
% ./dist/build/Lens-Aeson-test/Lens-Aeson-test
a value: Number 1
b value: Number 3
{"a": 1, "b": 3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment