Safe Haskell | None |
---|---|
Language | Haskell2010 |
Minimal JavaScript Object Notation (JSON) support as per RFC 8259.
This API provides a subset (with a couple of divergences; see below) of aeson API but puts the emphasis on simplicity rather than performance and features.
The ToJSON
and FromJSON
instances are intended to have an encoding
compatible with aeson
's encoding.
Limitations and divergences from aeson
's API
In order to reduce the dependency footprint and keep the code
simpler, the following divergences from the aeson
API have to be
made:
- There are no
FromJSON
/ToJSON
instances forChar
&String
. - The type synonym (& the constructor of the same name)
Object
usescontainers
'sMap
rather than aHashMap
unordered-containers
. Array
is represented by an ordinary list rather than aVector
from thevector
package.Number
usesDouble
instead ofScientific
- data Value
- type Object = Map Text Value
- type Pair = (Text, Value)
- (.=) :: ToJSON v => Text -> v -> Pair
- object :: [Pair] -> Value
- emptyArray :: Value
- emptyObject :: Value
- (.:) :: FromJSON a => Object -> Text -> Parser a
- (.:?) :: FromJSON a => Object -> Text -> Parser (Maybe a)
- (.:!) :: FromJSON a => Object -> Text -> Parser (Maybe a)
- (.!=) :: Parser (Maybe a) -> a -> Parser a
- encode :: ToJSON a => a -> ByteString
- encodeStrict :: ToJSON a => a -> ByteString
- encodeToBuilder :: ToJSON a => a -> Builder
- decodeStrict :: FromJSON a => ByteString -> Maybe a
- decode :: FromJSON a => ByteString -> Maybe a
- decodeStrictN :: FromJSON a => ByteString -> Maybe [a]
- withObject :: String -> (Object -> Parser a) -> Value -> Parser a
- withText :: String -> (Text -> Parser a) -> Value -> Parser a
- withArray :: String -> ([Value] -> Parser a) -> Value -> Parser a
- withNumber :: String -> (Double -> Parser a) -> Value -> Parser a
- withBool :: String -> (Bool -> Parser a) -> Value -> Parser a
- class FromJSON a where
- data Parser a
- parseMaybe :: (a -> Parser b) -> a -> Maybe b
- class ToJSON a where
Core JSON types
A JSON value represented as a Haskell value.
Constructors
emptyArray :: Value Source #
The empty JSON Array
(i.e. []
).
emptyObject :: Value Source #
The empty JSON Object
(i.e. {}
).
Accessors
Encoding and decoding
encode :: ToJSON a => a -> ByteString Source #
Serialise value as JSON/UTF-8-encoded lazy ByteString
encodeStrict :: ToJSON a => a -> ByteString Source #
Serialise value as JSON/UTF-8-encoded strict ByteString
decodeStrict :: FromJSON a => ByteString -> Maybe a Source #
Decode a single JSON document
decodeStrictN :: FromJSON a => ByteString -> Maybe [a] Source #
Decode multiple concatenated JSON documents
Prism-style parsers
Type conversion
class FromJSON a where Source #
A type that JSON can be deserialised into
FromJSON Bool Source # | |
FromJSON Double Source # | |
FromJSON Float Source # | |
FromJSON Int Source # | |
FromJSON Int8 Source # | |
FromJSON Int16 Source # | |
FromJSON Int32 Source # | |
FromJSON Int64 Source # | |
FromJSON Integer Source # | |
FromJSON Ordering Source # | |
FromJSON Word Source # | |
FromJSON Word8 Source # | |
FromJSON Word16 Source # | |
FromJSON Word32 Source # | |
FromJSON Word64 Source # | |
FromJSON () Source # | |
FromJSON Text Source # | |
FromJSON Text Source # | |
FromJSON Value Source # | |
FromJSON a => FromJSON [a] Source # | |
FromJSON a => FromJSON (Maybe a) Source # | |
(FromJSON a, FromJSON b) => FromJSON (a, b) Source # | |
FromJSON v => FromJSON (Map Text v) Source # | |
(FromJSON a, FromJSON b, FromJSON c) => FromJSON (a, b, c) Source # | |
(FromJSON a, FromJSON b, FromJSON c, FromJSON d) => FromJSON (a, b, c, d) Source # | |
parseMaybe :: (a -> Parser b) -> a -> Maybe b Source #
Run Parser
.
A common use-case is
.parseMaybe
parseJSON
A type that can be converted to JSON.
ToJSON Bool Source # | |
ToJSON Double Source # | |
ToJSON Float Source # | |
ToJSON Int Source # | |
ToJSON Int8 Source # | |
ToJSON Int16 Source # | |
ToJSON Int32 Source # | |
ToJSON Int64 Source # | Possibly lossy due to conversion to |
ToJSON Integer Source # | Possibly lossy due to conversion to |
ToJSON Word Source # | |
ToJSON Word8 Source # | |
ToJSON Word16 Source # | |
ToJSON Word32 Source # | |
ToJSON Word64 Source # | Possibly lossy due to conversion to |
ToJSON () Source # | |
ToJSON Text Source # | |
ToJSON Text Source # | |
ToJSON Value Source # | |
ToJSON a => ToJSON [a] Source # | |
ToJSON a => ToJSON (Maybe a) Source # | |
(ToJSON a, ToJSON b) => ToJSON (a, b) Source # | |
ToJSON v => ToJSON (Map Text v) Source # | |
(ToJSON a, ToJSON b, ToJSON c) => ToJSON (a, b, c) Source # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON (a, b, c, d) Source # | |