aeson-2.2.1.0: Fast JSON parsing and encoding

Safe Haskell | None
Language | Haskell2010

Data.Aeson.Encoding.Internal

Contents

- Encoding
- Predicates
- Encoding constructors
  - Decimal numbers
  - Decimal numbers as Text
  - Time
  - value
  - JSON tokens

Synopsis

- newtype Encoding' tag = Encoding {
  - fromEncoding :: Builder
  }
- type Encoding = Encoding' Value
- encodingToLazyByteString :: Encoding' a -> ByteString
- unsafeToEncoding :: Builder -> Encoding' a
- retagEncoding :: Encoding' a -> Encoding' b
- data Series
  - = Empty
  - | Value (Encoding' Series)
- pairs :: Series -> Encoding
- pair :: Key -> Encoding -> Series
- pairStr :: String -> Encoding -> Series
- unsafePairSBS :: ShortByteString -> Encoding -> Series
- pair' :: Encoding' Key -> Encoding -> Series
- nullEncoding :: Encoding' a -> Bool
- emptyArray_ :: Encoding
- emptyObject_ :: Encoding
- wrapObject :: Encoding' a -> Encoding
- wrapArray :: Encoding' a -> Encoding
- null_ :: Encoding
- bool :: Bool -> Encoding
- key :: Key -> Encoding' a
- text :: Text -> Encoding' a
- lazyText :: Text -> Encoding' a
- shortText :: ShortText -> Encoding' a
- string :: String -> Encoding' a
- list :: (a -> Encoding) -> [a] -> Encoding
- dict :: (k -> Encoding' Key) -> (v -> Encoding) -> (forall a. (k -> v -> a -> a) -> a -> m -> a) -> m -> Encoding
- tuple :: Encoding' InArray -> Encoding
- (>*<) :: Encoding' a -> Encoding' b -> Encoding' InArray
- data InArray
- empty :: Encoding' a
- (><) :: Encoding' a -> Encoding' a -> Encoding' a
- econcat :: [Encoding' a] -> Encoding' a
- int8 :: Int8 -> Encoding
- int16 :: Int16 -> Encoding
- int32 :: Int32 -> Encoding
- int64 :: Int64 -> Encoding
- int :: Int -> Encoding
- word8 :: Word8 -> Encoding
- word16 :: Word16 -> Encoding
- word32 :: Word32 -> Encoding
- word64 :: Word64 -> Encoding
- word :: Word -> Encoding
- integer :: Integer -> Encoding
- float :: Float -> Encoding
- double :: Double -> Encoding
- scientific :: Scientific -> Encoding
- int8Text :: Int8 -> Encoding' a
- int16Text :: Int16 -> Encoding' a
- int32Text :: Int32 -> Encoding' a
- int64Text :: Int64 -> Encoding' a
- intText :: Int -> Encoding' a
- word8Text :: Word8 -> Encoding' a
- word16Text :: Word16 -> Encoding' a
- word32Text :: Word32 -> Encoding' a
- word64Text :: Word64 -> Encoding' a
- wordText :: Word -> Encoding' a
- integerText :: Integer -> Encoding' a
- floatText :: Float -> Encoding' a
- doubleText :: Double -> Encoding' a
- scientificText :: Scientific -> Encoding' a
- day :: Day -> Encoding' a
- month :: Month -> Encoding' a
- quarter :: Quarter -> Encoding' a
- localTime :: LocalTime -> Encoding' a
- utcTime :: UTCTime -> Encoding' a
- timeOfDay :: TimeOfDay -> Encoding' a
- zonedTime :: ZonedTime -> Encoding' a
- value :: Value -> Encoding
- comma :: Encoding' a
- colon :: Encoding' a
- openBracket :: Encoding' a
- closeBracket :: Encoding' a
- openCurly :: Encoding' a
- closeCurly :: Encoding' a

# Encoding

newtype Encoding' tag #

An encoding of a JSON value.

`tag` represents which kind of JSON the Encoding is encoding to, we reuse `Text` and `Value` as tags here.

Constructors

Encoding |

Fields

- fromEncoding :: Builder

  Acquire the underlying bytestring builder.

#### Instances

Instances details

KeyValue Encoding Series # |
Instance details Defined in Data.Aeson.Types.ToJSON Methods (.=) :: ToJSON v => Key -> v -> Series # explicitToField :: (v -> Encoding) -> Key -> v -> Series #
KeyValueOmit Encoding Series # |
Instance details Defined in Data.Aeson.Types.ToJSON Methods (.?=) :: ToJSON v => Key -> v -> Series # explicitToFieldOmit :: (v -> Bool) -> (v -> Encoding) -> Key -> v -> Series #
GToJSON' Encoding arity (U1 :: Type -> Type) # |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Encoding arity a -> U1 a -> Encoding
GToJSON' Encoding arity (V1 :: Type -> Type) # |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Encoding arity a -> V1 a -> Encoding
ToJSON1 f => GToJSON' Encoding One (Rec1 f) # |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Encoding One a -> Rec1 f a -> Encoding
(EncodeProduct arity a, EncodeProduct arity b) => GToJSON' Encoding arity (a :*: b) # |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Encoding arity a0 -> (a :*: b) a0 -> Encoding
ToJSON a => GToJSON' Encoding arity (K1 i a :: Type -> Type) # |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Encoding arity a0 -> K1 i a a0 -> Encoding
(ToJSON1 f, GToJSON' Encoding One g) => GToJSON' Encoding One (f :.: g) # |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Encoding One a -> (f :.: g) a -> Encoding
IsString (Encoding' a) # | Since: 2.2.0.0
Instance details Defined in Data.Aeson.Encoding.Internal Methods fromString :: String -> Encoding' a #
Show (Encoding' a) # |
Instance details Defined in Data.Aeson.Encoding.Internal Methods showsPrec :: Int -> Encoding' a -> ShowS # show :: Encoding' a -> String # showList :: [Encoding' a] -> ShowS #
Eq (Encoding' a) # |
Instance details Defined in Data.Aeson.Encoding.Internal Methods (==) :: Encoding' a -> Encoding' a -> Bool # (/=) :: Encoding' a -> Encoding' a -> Bool #
Ord (Encoding' a) # |
Instance details Defined in Data.Aeson.Encoding.Internal Methods compare :: Encoding' a -> Encoding' a -> Ordering # (<) :: Encoding' a -> Encoding' a -> Bool # (<=) :: Encoding' a -> Encoding' a -> Bool # (>) :: Encoding' a -> Encoding' a -> Bool # (>=) :: Encoding' a -> Encoding' a -> Bool # max :: Encoding' a -> Encoding' a -> Encoding' a # min :: Encoding' a -> Encoding' a -> Encoding' a #

type Encoding = Encoding' Value #

Often used synonym for `Encoding'`.

encodingToLazyByteString :: Encoding' a -> ByteString #

unsafeToEncoding :: Builder -> Encoding' a #

Make Encoding from Builder.

Use with care! You have to make sure that the passed Builder is a valid JSON Encoding!

retagEncoding :: Encoding' a -> Encoding' b #

data Series #

A series of values that, when encoded, should be separated by commas. Since 0.11.0.0, the `.=` operator is overloaded to create either `(Text, Value)` or `Series`. You can use Series when encoding directly to a bytestring builder as in the following example:

    toEncoding (Person name age) = pairs ("name" .= name <> "age" .= age)

Constructors

Empty |
Value (Encoding' Series) |

#### Instances

Instances details

Monoid Series # |
Instance details Defined in Data.Aeson.Encoding.Internal Methods mempty :: Series # mappend :: Series -> Series -> Series # mconcat :: [Series] -> Series #
Semigroup Series # |
Instance details Defined in Data.Aeson.Encoding.Internal Methods (<>) :: Series -> Series -> Series # sconcat :: NonEmpty Series -> Series # stimes :: Integral b => b -> Series -> Series #
KeyValue Encoding Series # |
Instance details Defined in Data.Aeson.Types.ToJSON Methods (.=) :: ToJSON v => Key -> v -> Series # explicitToField :: (v -> Encoding) -> Key -> v -> Series #
KeyValueOmit Encoding Series # |
Instance details Defined in Data.Aeson.Types.ToJSON Methods (.?=) :: ToJSON v => Key -> v -> Series # explicitToFieldOmit :: (v -> Bool) -> (v -> Encoding) -> Key -> v -> Series #

pairs :: Series -> Encoding #

Encode a series of key/value pairs, separated by commas.

pair :: Key -> Encoding -> Series #

pairStr :: String -> Encoding -> Series #

unsafePairSBS :: ShortByteString -> Encoding -> Series #

A variant of a `pair` where key is already encoded including the quotes and colon.

    pair "foo" v = unsafePair "\"foo\":" v

Since: 2.0.3.0

pair' :: Encoding' Key -> Encoding -> Series #

# Predicates

nullEncoding :: Encoding' a -> Bool #

# Encoding constructors

emptyArray_ :: Encoding #

emptyObject_ :: Encoding #

wrapObject :: Encoding' a -> Encoding #

wrapArray :: Encoding' a -> Encoding #

null_ :: Encoding #

bool :: Bool -> Encoding #

key :: Key -> Encoding' a #

text :: Text -> Encoding' a #

lazyText :: Text -> Encoding' a #

shortText :: ShortText -> Encoding' a #

Since: 2.0.2.0

string :: String -> Encoding' a #

list :: (a -> Encoding) -> [a] -> Encoding #

dict #

Arguments

:: (k -> Encoding' Key) | key encoding
-> (v -> Encoding) | value encoding
-> (forall a. (k -> v -> a -> a) -> a -> m -> a) | `foldrWithKey` - indexed fold
-> m | container
-> Encoding |

Encode as JSON object

tuple :: Encoding' InArray -> Encoding #

Encode as a tuple.

@ toEncoding (X a b c) = tuple $ toEncoding a >*< toEncoding b >*< toEncoding c

(>*<) :: Encoding' a -> Encoding' b -> Encoding' InArray infixr 6 #

See `tuple`.

data InArray #

Type tag for tuples contents, see `tuple`.

empty :: Encoding' a #

(><) :: Encoding' a -> Encoding' a -> Encoding' a infixr 6 #

econcat :: [Encoding' a] -> Encoding' a #

## Decimal numbers

int8 :: Int8 -> Encoding #

int16 :: Int16 -> Encoding #

int32 :: Int32 -> Encoding #

int64 :: Int64 -> Encoding #

int :: Int -> Encoding #

word8 :: Word8 -> Encoding #

word16 :: Word16 -> Encoding #

word32 :: Word32 -> Encoding #

word64 :: Word64 -> Encoding #

word :: Word -> Encoding #

integer :: Integer -> Encoding #

float :: Float -> Encoding #

double :: Double -> Encoding #

    >>> double 42
    "42.0"

    >>> double (0/0)
    "null"

    >>> double (1/0)
    "\"+inf\""

    >>> double (-23/0)
    "\"-inf\""

scientific :: Scientific -> Encoding #

## Decimal numbers as Text

int8Text :: Int8 -> Encoding' a #

int16Text :: Int16 -> Encoding' a #

int32Text :: Int32 -> Encoding' a #

int64Text :: Int64 -> Encoding' a #

intText :: Int -> Encoding' a #

word8Text :: Word8 -> Encoding' a #

word16Text :: Word16 -> Encoding' a #

word32Text :: Word32 -> Encoding' a #

word64Text :: Word64 -> Encoding' a #

wordText :: Word -> Encoding' a #

integerText :: Integer -> Encoding' a #

floatText :: Float -> Encoding' a #

doubleText :: Double -> Encoding' a #

    >>> doubleText 42
    "\"42.0\""

    >>> doubleText (0/0)
    "\"NaN\""

    >>> doubleText (1/0)
    "\"+inf\""

    >>> doubleText (-23/0)
    "\"-inf\""

scientificText :: Scientific -> Encoding' a #

## Time

day :: Day -> Encoding' a #

month :: Month -> Encoding' a #

quarter :: Quarter -> Encoding' a #

localTime :: LocalTime -> Encoding' a #

utcTime :: UTCTime -> Encoding' a #

timeOfDay :: TimeOfDay -> Encoding' a #

zonedTime :: ZonedTime -> Encoding' a #

## value

value :: Value -> Encoding #

## JSON tokens

comma :: Encoding' a #

colon :: Encoding' a #

openBracket :: Encoding' a #

closeBracket :: Encoding' a #

openCurly :: Encoding' a #

closeCurly :: Encoding' a #