Safe Haskell | Safe-Inferred |
---|---|
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
&Value
. - The type synonym (& the constructor of the same name)
Value
usescontainers
'sMap
rather than aHashMap
unordered-containers
. Array
is represented by an ordinary list rather than aVector
from thevector
package.Number
usesDouble
instead ofScientific
Synopsis
- 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.
Instances
Constructors
emptyArray :: Value Source #
The empty JSON Array
(i.e. []
).
emptyObject :: Value Source #
The empty JSON Value
(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
Instances
FromJSON Int16 Source # | |
FromJSON Int32 Source # | |
FromJSON Int64 Source # | |
FromJSON Int8 Source # | |
FromJSON Word16 Source # | |
FromJSON Word32 Source # | |
FromJSON Word64 Source # | |
FromJSON Word8 Source # | |
FromJSON Ordering Source # | |
FromJSON Value Source # | |
FromJSON Text Source # | |
FromJSON Text Source # | |
FromJSON Integer Source # | |
FromJSON () Source # | |
FromJSON Bool Source # | |
FromJSON Double Source # | |
FromJSON Float Source # | |
FromJSON Int Source # | |
FromJSON Word Source # | |
FromJSON a => FromJSON (Maybe a) Source # | |
FromJSON a => FromJSON [a] Source # | |
FromJSON v => FromJSON (Map Text v) Source # | |
(FromJSON a, FromJSON b) => FromJSON (a, b) 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.
Instances
ToJSON Int16 Source # | |
ToJSON Int32 Source # | |
ToJSON Int64 Source # | Possibly lossy due to conversion to |
ToJSON Int8 Source # | |
ToJSON Word16 Source # | |
ToJSON Word32 Source # | |
ToJSON Word64 Source # | Possibly lossy due to conversion to |
ToJSON Word8 Source # | |
ToJSON Value Source # | |
ToJSON Text Source # | |
ToJSON Text Source # | |
ToJSON Integer Source # | Possibly lossy due to conversion to |
ToJSON () Source # | |
Defined in Data.Aeson.Micro | |
ToJSON Bool Source # | |
ToJSON Double Source # | |
ToJSON Float Source # | |
ToJSON Int Source # | |
ToJSON Word Source # | |
ToJSON a => ToJSON (Maybe a) Source # | |
ToJSON a => ToJSON [a] Source # | |
Defined in Data.Aeson.Micro | |
ToJSON v => ToJSON (Map Text v) Source # | |
(ToJSON a, ToJSON b) => ToJSON (a, b) Source # | |
Defined in Data.Aeson.Micro | |
(ToJSON a, ToJSON b, ToJSON c) => ToJSON (a, b, c) Source # | |
Defined in Data.Aeson.Micro | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON (a, b, c, d) Source # | |
Defined in Data.Aeson.Micro |