Add print function
This commit is contained in:
parent
6a39873912
commit
8d1cb7b3ef
12
Json.hs
12
Json.hs
@ -1,4 +1,9 @@
|
||||
module Json where
|
||||
module Json
|
||||
( (|.)
|
||||
, (|:)
|
||||
, repr
|
||||
, jprint
|
||||
) where
|
||||
|
||||
import Data.Aeson
|
||||
import Data.Aeson.Types (parse)
|
||||
@ -15,6 +20,7 @@ obj |. key = case parse (.: key) obj of
|
||||
Error err -> toJSON err
|
||||
|
||||
-- Get the String value of a key
|
||||
|
||||
(|:) :: Object -> Text -> String
|
||||
obj |: key = repr' (obj |. key) 0
|
||||
|
||||
@ -36,3 +42,7 @@ repr' val lev =
|
||||
indent = '\n' : (concat . replicate lev) " "
|
||||
dump o k = concat [indent, unpack k, ": ", repr' (o |. k) (lev+1)]
|
||||
mapl f v = V.toList $ V.map f v
|
||||
|
||||
-- Print a representation of a JSON Value
|
||||
jprint :: Value -> IO ()
|
||||
jprint = putStrLn . repr
|
Loading…
Reference in New Issue
Block a user