Z-Data-0.8.4.0: Array, vector and text
Copyright(c) Dong Han 2019
LicenseBSD
Maintainerwinterland1989@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Z.Data.JSON.Builder

Description

This module provides builders for JSON Values, a Haskell JSON representation. These builders are designed to comply with rfc8258. Only control characters are escaped, other unicode codepoints are directly written instead of being escaped.

Synopsis

Value Builders

value :: Value -> Builder () Source #

Encode a Value, you can use this function with toValue to get encodeJSON with a small overhead.

object' :: (a -> Builder ()) -> Vector (Text, a) -> Builder () Source #

array' :: (a -> Builder ()) -> Vector a -> Builder () Source #

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"
   '"':  "\""
   '\':  "\\"
   'DEL':  "\u007f"
   other chars <= 0x1F: "\u00XX"

prettyValue :: Value -> Builder () Source #

'ValuePretty'' with 4 spaces indentation per level, e.g.

{
    "results":
    [
        {
            "from_user_id_str":"80430860",
            "profile_image_url":"http://a2.twimg.com/profile_images/536455139/icon32_normal.png",
            "created_at":"Wed, 26 Jan 2011 07:07:02 +0000",
            "from_user":"kazu_yamamoto",
            "id_str":"30159761706061824",
            "metadata":
            {
                "result_type":"recent"
            },
            "to_user_id":null,
            "text":"Haskell Server Pages って、まだ続いていたのか!",
            "id":30159761706061824,
            "from_user_id":80430860,
            "geo":null,
            "iso_language_code":"no",
            "to_user_id_str":null,
            "source":"&lt;a href=&quot;http:/twitter.com&quot;&gt;web&lt;/a&gt;"
        }
    ],
    "max_id":30159761706061824,
    "since_id":0,
    "refresh_url":"?since_id=30159761706061824&q=haskell",
    "next_page":"?page=2&max_id=30159761706061824&rpp=1&q=haskell",
    "results_per_page":1,
    "page":1,
    "completed_in":1.2606e-2,
    "since_id_str":"0",
    "max_id_str":"30159761706061824",
    "query":"haskell"
}

prettyValue' Source #

Arguments

:: Int

indentation per level

-> Int

initial indentation

-> Value 
-> Builder () 

Encode a Value with indentation and linefeed.

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

data Value Source #

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.

Instances

Instances details
Eq Value Source # 
Instance details

Defined in Z.Data.JSON.Value

Methods

(==) :: Value -> Value -> Bool #

(/=) :: Value -> Value -> Bool #

Ord Value Source # 
Instance details

Defined in Z.Data.JSON.Value

Methods

compare :: Value -> Value -> Ordering #

(<) :: Value -> Value -> Bool #

(<=) :: Value -> Value -> Bool #

(>) :: Value -> Value -> Bool #

(>=) :: Value -> Value -> Bool #

max :: Value -> Value -> Value #

min :: Value -> Value -> Value #

Show Value Source # 
Instance details

Defined in Z.Data.JSON.Value

Methods

showsPrec :: Int -> Value -> ShowS #

show :: Value -> String #

showList :: [Value] -> ShowS #

Generic Value Source # 
Instance details

Defined in Z.Data.JSON.Value

Associated Types

type Rep Value :: Type -> Type #

Methods

from :: Value -> Rep Value x #

to :: Rep Value x -> Value #

Arbitrary Value Source # 
Instance details

Defined in Z.Data.JSON.Value

Methods

arbitrary :: Gen Value #

shrink :: Value -> [Value] #

NFData Value Source # 
Instance details

Defined in Z.Data.JSON.Value

Methods

rnf :: Value -> () #

Print Value Source # 
Instance details

Defined in Z.Data.JSON.Value

Methods

toUTF8BuilderP :: Int -> Value -> Builder () Source #

JSON Value Source # 
Instance details

Defined in Z.Data.JSON.Base

type Rep Value Source # 
Instance details

Defined in Z.Data.JSON.Value