Guest User

Untitled

a guest
Apr 25th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. {-# LANGUAGE OverloadedStrings #-}
  2.  
  3. module Test06 where
  4.  
  5. import Prelude hiding (readFile, lookup)
  6.  
  7. import Control.Monad.IO.Class
  8. import Control.Lens
  9. import Data.Aeson
  10. import Data.Aeson.Lens
  11. import qualified Data.ByteString as B
  12.  
  13. main :: IO ()
  14. main = do
  15. val <- B.readFile "test/Data/test01.json"
  16. print val
  17. print $ val ^? key "lng" . nonNull
  18. print $ val ^? key "lng" . _String
  19. print $ val ^? key "resources" . _Object
  20. print $ val ^? key "resources" . key "en" . key "translation" . _Object
  21. print $ val ^? key "resources" . key "en" . key "translation" . key "look" . key "deep" . _Value
  22. print $ val ^? (foldl (.) _Value $ map key ["resources" , "en", "translation"])
  23.  
  24. {-
  25. test/Data/test01.json
  26.  
  27. {
  28. "lng": "en",
  29. "debug": true,
  30. "resources": {
  31. "en": {
  32. "translation" : {
  33. "key": "value of key",
  34. "look": {
  35. "deep": "value of look deep"
  36. }
  37. }
  38. }
  39. }
  40. }
  41.  
  42. -}
Add Comment
Please, Sign In to add comment