Skip to content

Instantly share code, notes, and snippets.

Last active Jan 25, 2016
What would you like to do?
use JSON files as if they were Haskell values / live life maximally with simple language semantics
"hello": "world",
"this": {
"can": {
"be": "nested"
#!/usr/bin/env stack
-- stack --resolver lts-4.2 --install-ghc runghc --package file-embed --package aeson --package lens --package lens-aeson
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module JSONBaby where
import Control.Lens
import Data.Aeson
import Data.Aeson.Lens
import Data.FileEmbed
value :: Maybe Value
value = (decode . view lazy) $(embedFile "a.json")
main :: IO ()
main = do
print value
print (value ^? _Just . key "hello")
print (value ^? _Just . key "this" . key "can" . key "be")
Just (Object (fromList [("hello",String "world"),("this",Object (fromList [("can",Object (fromList [("be",String "nested")]))]))]))
Just (String "world")
Just (String "nested")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment