Safe Haskell | None |
---|---|
Language | Haskell2010 |
Simple DSL for mapping Haskell values into JSON representation and
rendering it into ByteString
.
Synopsis
- toByteString :: Json -> ByteString
- toWrite :: Json -> Write
- data Json
- null :: Json
- bool :: Bool -> Json
- intNumber :: Int -> Json
- wordNumber :: Word -> Json
- doubleNumber :: Double -> Json
- scientificNumber :: Scientific -> Json
- textString :: Text -> Json
- scientificString :: Scientific -> Json
- array :: Foldable f => f Json -> Json
- object :: Foldable f => f (Text, Json) -> Json
- fromByteString :: ByteString -> Json
- fromWrite :: Write -> Json
Execution
toByteString :: Json -> ByteString Source #
Render a JSON value into strict bytestring.
Json
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
Numbers
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.
object :: Foldable f => f (Text, Json) -> Json Source #
JSON Object literal from a foldable over pairs of key to value literal.
Low-level
fromByteString :: ByteString -> Json Source #
Any JSON literal manually rendered as ByteString.
This is a low-level function allowing to avoid unnecessary processing in cases where you already have a rendered JSON at hand.
Warning:
It is your responsibility to ensure that the content is correct JSON.
fromWrite :: Write -> Json Source #
Any JSON literal manually rendered as Write.
This is a low-level function allowing to avoid unnecessary processing in cases where you already have a rendered JSON at hand.
You can think of Write as a specialized version of ByteString builder.
You can efficiently convert a ByteString to Write using byteString
,
making it possible to have parts of the JSON value tree rendered using other libraries.
You can as well manually implement encoders for your custom types.
Warning:
It is your responsibility to ensure that the content is correct, otherwise you may produce invalid JSON.