| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Json.Parser
Contents
- parseJsonBs :: JsonReadable t => ByteString -> Either String t
- parseJsonBsl :: JsonReadable t => ByteString -> Either String t
- parseJsonT :: JsonReadable t => Text -> Either String t
- class JsonReadable t where
- runSpec :: HVectElim ts x -> ObjSpec ts -> Parser x
- data ObjSpec ts where
- ObjSpecNil :: ObjSpec []
- (:&&:) :: (JsonReadable t, Typeable t) => !(TypedKey t) -> !(ObjSpec ts) -> ObjSpec (t : ts)
- data TypedKey t
- reqKey :: Typeable t => Text -> TypedKey t
- optKey :: Typeable t => Text -> TypedKey (Maybe t)
- readObject :: (Text -> Maybe (Parser WrappedValue)) -> Parser (HashMap Text WrappedValue)
- data WrappedValue = forall t . (Typeable t, JsonReadable t) => WrappedValue !t
- getValueByKey :: (Monad m, Typeable t) => Text -> HashMap Text WrappedValue -> m t
- getOptValueByKey :: (Monad m, Typeable t) => Text -> HashMap Text WrappedValue -> m (Maybe t)
Parsing from different types
parseJsonBs :: JsonReadable t => ByteString -> Either String t Source
Parse json from a strict ByteString
parseJsonBsl :: JsonReadable t => ByteString -> Either String t Source
Parse json from a lazy ByteString
parseJsonT :: JsonReadable t => Text -> Either String t Source
Parse json from a strict Text
Description how to parse JSON to a Haskell type
class JsonReadable t where Source
Typeclass defining an attoparsec Parser how Haskell types should
be parsed from JSON. Use predifined instances (with readJson) and
runSpec (on ObjSpec) to define instances for custom types
Instances
DSL to easily create parser for custom Haskell types
Constructors
| ObjSpecNil :: ObjSpec [] | |
| (:&&:) :: (JsonReadable t, Typeable t) => !(TypedKey t) -> !(ObjSpec ts) -> ObjSpec (t : ts) infixr 5 |
Json object key to a value t
reqKey :: Typeable t => Text -> TypedKey t Source
Required json object key. Use IsString instance for automatic choice
optKey :: Typeable t => Text -> TypedKey (Maybe t) Source
Optional json object key. Use IsString instance for automatic choice
Low level JSON parsing helpers
readObject :: (Text -> Maybe (Parser WrappedValue)) -> Parser (HashMap Text WrappedValue) Source
Parse a json object given a value parser for each key
data WrappedValue Source
A value that is Typeable and JsonReadable
Constructors
| forall t . (Typeable t, JsonReadable t) => WrappedValue !t |
getValueByKey :: (Monad m, Typeable t) => Text -> HashMap Text WrappedValue -> m t Source
Get a value out of the map returned by readObject
getOptValueByKey :: (Monad m, Typeable t) => Text -> HashMap Text WrappedValue -> m (Maybe t) Source
Optionally get a value out of the map returned by readObject