jsonifier-0.1.0.6: Fast and simple JSON encoding toolkit
Safe HaskellNone
LanguageHaskell2010

Jsonifier

Description

Simple DSL for mapping Haskell values into JSON representation and rendering it into ByteString.

Synopsis

ByteString

toByteString :: Json -> ByteString Source #

Render a JSON value into strict bytestring.

Json

data Json Source #

Specification of how to render a JSON value to ByteString. Sort of a JSON-specialized ByteString builder.

You can construct it from Haskell types using the specialized conversion functions like intNumber, textString or object. After constructing, you can convert to strict ByteString using the toByteString function.

Primitives

null :: Json Source #

JSON Null literal.

bool :: Bool -> Json Source #

JSON Boolean literal.

Numbers

intNumber :: Int -> Json Source #

JSON Number literal from Int.

wordNumber :: Word -> Json Source #

JSON Number literal from Word.

doubleNumber :: Double -> Json Source #

JSON Number literal from Double.

Since JSON doesn't have support for them, non-real values like NaN, Infinity, -Infinity get rendered as 0.

scientificNumber :: Scientific -> Json Source #

JSON Number literal from Scientific.

Strings

textString :: Text -> Json Source #

JSON String literal from Text.

scientificString :: Scientific -> Json Source #

JSON String literal from Scientific.

You may need this when the reader of your JSON cannot handle large number literals.

Composites

array :: Foldable f => f Json -> Json Source #

JSON Array literal from a foldable over element literals.

Don't be afraid to use fmap to map the elements of the input datastructure, it will all be optimized away.

object :: Foldable f => f (Text, Json) -> Json Source #

JSON Object literal from a foldable over pairs of key to value literal.

Don't be afraid to use fmap to map the elements of the input datastructure, it will all be optimized away.