Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.Aeson.Micro
Description
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
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 #
The empty JSON Array
(i.e. []
).
emptyObject :: Value #
The empty JSON Object
(i.e. {}
).
Accessors
Encoding and decoding
encode :: ToJSON a => a -> ByteString #
Serialise value as JSON/UTF-8-encoded lazy ByteString
encodeStrict :: ToJSON a => a -> ByteString #
Serialise value as JSON/UTF-8-encoded strict ByteString
encodeToBuilder :: ToJSON a => a -> Builder #
Serialise value as JSON/UTF8-encoded Builder
decodeStrict :: FromJSON a => ByteString -> Maybe a #
Decode a single JSON document
decode :: FromJSON a => ByteString -> Maybe a #
Decode a single JSON document
decodeStrictN :: FromJSON a => ByteString -> Maybe [a] #
Decode multiple concatenated JSON documents
Prism-style parsers
Type conversion
A type that JSON can be deserialised into
Instances
FromJSON Int16 # | |
FromJSON Int32 # | |
FromJSON Int64 # | |
FromJSON Int8 # | |
FromJSON Word16 # | |
FromJSON Word32 # | |
FromJSON Word64 # | |
FromJSON Word8 # | |
FromJSON Ordering # | |
FromJSON Value # | |
FromJSON Text # | |
FromJSON Text # | |
FromJSON Integer # | |
FromJSON () # | |
Defined in Data.Aeson.Micro | |
FromJSON Bool # | |
FromJSON Double # | |
FromJSON Float # | |
FromJSON Int # | |
FromJSON Word # | |
FromJSON a => FromJSON (Maybe a) # | |
FromJSON a => FromJSON [a] # | |
Defined in Data.Aeson.Micro | |
FromJSON v => FromJSON (Map Text v) # | |
(FromJSON a, FromJSON b) => FromJSON (a, b) # | |
Defined in Data.Aeson.Micro | |
(FromJSON a, FromJSON b, FromJSON c) => FromJSON (a, b, c) # | |
Defined in Data.Aeson.Micro | |
(FromJSON a, FromJSON b, FromJSON c, FromJSON d) => FromJSON (a, b, c, d) # | |
Defined in Data.Aeson.Micro |
parseMaybe :: (a -> Parser b) -> a -> Maybe b #
Run Parser
.
A common use-case is
.parseMaybe
parseJSON
A type that can be converted to JSON.
Instances
ToJSON Int16 # | |
Defined in Data.Aeson.Micro | |
ToJSON Int32 # | |
Defined in Data.Aeson.Micro | |
ToJSON Int64 # | Possibly lossy due to conversion to |
Defined in Data.Aeson.Micro | |
ToJSON Int8 # | |
Defined in Data.Aeson.Micro | |
ToJSON Word16 # | |
Defined in Data.Aeson.Micro | |
ToJSON Word32 # | |
Defined in Data.Aeson.Micro | |
ToJSON Word64 # | Possibly lossy due to conversion to |
Defined in Data.Aeson.Micro | |
ToJSON Word8 # | |
Defined in Data.Aeson.Micro | |
ToJSON Value # | |
Defined in Data.Aeson.Micro | |
ToJSON Text # | |
Defined in Data.Aeson.Micro | |
ToJSON Text # | |
Defined in Data.Aeson.Micro | |
ToJSON Integer # | Possibly lossy due to conversion to |
Defined in Data.Aeson.Micro | |
ToJSON () # | |
Defined in Data.Aeson.Micro | |
ToJSON Bool # | |
Defined in Data.Aeson.Micro | |
ToJSON Double # | |
Defined in Data.Aeson.Micro | |
ToJSON Float # | |
Defined in Data.Aeson.Micro | |
ToJSON Int # | |
Defined in Data.Aeson.Micro | |
ToJSON Word # | |
Defined in Data.Aeson.Micro | |
ToJSON a => ToJSON (Maybe a) # | |
Defined in Data.Aeson.Micro | |
ToJSON a => ToJSON [a] # | |
Defined in Data.Aeson.Micro | |
ToJSON v => ToJSON (Map Text v) # | |
(ToJSON a, ToJSON b) => ToJSON (a, b) # | |
Defined in Data.Aeson.Micro | |
(ToJSON a, ToJSON b, ToJSON c) => ToJSON (a, b, c) # | |
Defined in Data.Aeson.Micro | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON (a, b, c, d) # | |
Defined in Data.Aeson.Micro |