Skip to content

Instantly share code, notes, and snippets.

@rahulmutt
Created August 2, 2017 03:07
Show Gist options
  • Save rahulmutt/d9d64c45e58b61628a4fb6a6852ecc52 to your computer and use it in GitHub Desktop.
Save rahulmutt/d9d64c45e58b61628a4fb6a6852ecc52 to your computer and use it in GitHub Desktop.
Lens Example in Eta
module Main where
import Control.Lens
import Data.Aeson
import Data.Aeson.Lens
import Data.Aeson.Encode.Pretty
import qualified Data.ByteString.Lazy.Char8 as BS
main :: IO ()
main = do
let json = "[{\"clicks\":1},{\"clicks\":2},{\"clicks\":3}]"
json' = json & (values . members . _Integral) %~ (+50)
case decode json' :: Maybe Value of
Just value -> putStrLn $ BS.unpack $ encodePretty value
Nothing -> putStrLn "Bad JSON!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment