aeson-2.1.2.1: Fast JSON parsing and encoding
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Aeson.Encoding

Description

Functions in this module return well-formed Encoding'. Polymorphic variants, which return Encoding' a, return a textual JSON value, so it can be used as both Encoding' Text and Encoding' = Encoding' Value.

Synopsis

Encoding

type Encoding = Encoding' Value Source #

Often used synonym for Encoding'.

data Encoding' tag Source #

An encoding of a JSON value.

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

Instances

Instances details
GToJSON' Encoding arity (U1 :: Type -> Type) Source # 
Instance details

Defined in Data.Aeson.Types.ToJSON

Methods

gToJSON :: Options -> ToArgs Encoding arity a -> U1 a -> Encoding

GToJSON' Encoding arity (V1 :: Type -> Type) Source # 
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) Source # 
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) Source # 
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) Source # 
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) Source # 
Instance details

Defined in Data.Aeson.Types.ToJSON

Methods

gToJSON :: Options -> ToArgs Encoding One a -> (f :.: g) a -> Encoding

Show (Encoding' a) Source # 
Instance details

Defined in Data.Aeson.Encoding.Internal

Eq (Encoding' a) Source # 
Instance details

Defined in Data.Aeson.Encoding.Internal

Methods

(==) :: Encoding' a -> Encoding' a -> Bool #

(/=) :: Encoding' a -> Encoding' a -> Bool #

Ord (Encoding' a) Source # 
Instance details

Defined in Data.Aeson.Encoding.Internal

fromEncoding :: Encoding' tag -> Builder Source #

Acquire the underlying bytestring builder.

unsafeToEncoding :: Builder -> Encoding' a Source #

Make Encoding from Builder.

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

data Series Source #

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)

Instances

Instances details
KeyValue Series Source # 
Instance details

Defined in Data.Aeson.Types.ToJSON

Methods

(.=) :: ToJSON v => Key -> v -> Series Source #

Monoid Series Source # 
Instance details

Defined in Data.Aeson.Encoding.Internal

Semigroup Series Source # 
Instance details

Defined in Data.Aeson.Encoding.Internal

pairs :: Series -> Encoding Source #

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

Predicates

Encoding constructors

shortText :: ShortText -> Encoding' a Source #

Since: 2.0.2.0

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

dict Source #

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

Decimal numbers

double :: Double -> Encoding Source #

>>> double 42
"42.0"
>>> double (0/0)
"null"
>>> double (1/0)
"\"+inf\""
>>> double (-23/0)
"\"-inf\""

Decimal numbers as Text

doubleText :: Double -> Encoding' a Source #

>>> doubleText 42
"\"42.0\""
>>> doubleText (0/0)
"\"NaN\""
>>> doubleText (1/0)
"\"+inf\""
>>> doubleText (-23/0)
"\"-inf\""

Time

value