Copyright | (c) Dong Han 2019 |
---|---|
License | BSD |
Maintainer | winterland1989@gmail.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- value :: Value -> Builder ()
- object :: Vector (Text, Value) -> Builder ()
- object' :: (a -> Builder ()) -> Vector (Text, a) -> Builder ()
- array :: Vector Value -> Builder ()
- array' :: (a -> Builder ()) -> Vector a -> Builder ()
- string :: Text -> Builder ()
- scientific :: Scientific -> Builder ()
- kv :: Text -> Builder () -> Builder ()
- kv' :: Text -> Builder () -> Builder ()
- data Value
Value Builders
value :: Value -> Builder () Source #
Encode a Value
, you can use this function with toValue
to get encodeJSON
with a small overhead.
string :: Text -> Builder () Source #
Escape text into JSON string and add double quotes, escaping rules:
'\b': "\b" '\f': "\f" '\n': "\n" '\r': "\r" '\t': "\t" '"': "\"" '\': "\\" '/': "\/" other chars <= 0x1F: "\u00XX"
scientific :: Scientific -> Builder () Source #
This builder try to render integer when (0 <= e < 1024), and scientific notation otherwise.
Builder helpers
kv :: Text -> Builder () -> Builder () Source #
Use :
as separator to connect a label(no escape, only add quotes) with field builders.
Don't use chars which need escaped in label.
kv' :: Text -> Builder () -> Builder () Source #
Use :
as separator to connect a label(escape the label and add quotes) with field builders.
Re-export Value
type
A JSON value represented as a Haskell value.
The Object'
s payload is a key-value vector instead of a map, which parsed
directly from JSON document. This design choice has following advantages:
- Allow different strategies handling duplicated keys.
- Allow different
Map
type to do further parsing, e.g.FlatMap
- Roundtrip without touching the original key-value order.
- Save time if constructing map is not neccessary, e.g. using a linear scan to find a key if only that key is needed.
Object !(Vector (Text, Value)) | |
Array !(Vector Value) | |
String !Text | |
Number !Scientific | |
Bool !Bool | |
Null |