json-0.10: Support for serialising Haskell to and from JSON

Safe Haskell | Safe-Inferred
Language | Haskell98

Text.JSON.Types

Contents

- JSON Types
- Wrapper Types

Description

Basic support for working with JSON values.

Synopsis

- data JSValue
  - = JSNull
  - | JSBool !Bool
  - | JSRational Bool !Rational
  - | JSString JSString
  - | JSArray [JSValue]
  - | JSObject (JSObject JSValue)
- newtype JSString = JSONString {
  - fromJSString :: String
  }
- toJSString :: String -> JSString
- newtype JSObject e = JSONObject {
  - fromJSObject :: [(String, e)]
  }
- toJSObject :: [(String, a)] -> JSObject a
- get_field :: JSObject a -> String -> Maybe a
- set_field :: JSObject a -> String -> a -> JSObject a

# JSON Types

data JSValue Source #

JSON values

The type to which we encode Haskell values. There's a set of primitives, and a couple of heterogenous collection types.

Objects:

An object structure is represented as a pair of curly brackets surrounding zero or more name/value pairs (or members). A name is a string. A single colon comes after each name, separating the name from the value. A single comma separates a value from a following name.

Arrays:

An array structure is represented as square brackets surrounding zero or more values (or elements). Elements are separated by commas.

Only valid JSON can be constructed this way

Constructors

JSNull |
JSBool !Bool |
JSRational Bool !Rational |
JSString JSString |
JSArray [JSValue] |
JSObject (JSObject JSValue) |

#### Instances

Instances details

IsString JSValue Source # |
Instance details Defined in Text.JSON.Types Methods fromString :: String -> JSValue Source #
Read JSValue Source # |
Instance details Defined in Text.JSON.Types Methods readsPrec :: Int -> ReadS JSValue Source # readList :: ReadS [JSValue] Source # readPrec :: ReadPrec JSValue Source # readListPrec :: ReadPrec [JSValue] Source #
Show JSValue Source # |
Instance details Defined in Text.JSON.Types Methods showsPrec :: Int -> JSValue -> ShowS Source # show :: JSValue -> String Source # showList :: [JSValue] -> ShowS Source #
Eq JSValue Source # |
Instance details Defined in Text.JSON.Types Methods (==) :: JSValue -> JSValue -> Bool Source # (/=) :: JSValue -> JSValue -> Bool Source #
Ord JSValue Source # |
Instance details Defined in Text.JSON.Types Methods compare :: JSValue -> JSValue -> Ordering Source # (<) :: JSValue -> JSValue -> Bool Source # (<=) :: JSValue -> JSValue -> Bool Source # (>) :: JSValue -> JSValue -> Bool Source # (>=) :: JSValue -> JSValue -> Bool Source # max :: JSValue -> JSValue -> JSValue Source # min :: JSValue -> JSValue -> JSValue Source #
JSON JSValue Source # | To ensure we generate valid JSON, we map Haskell types to JSValue internally, then pretty print that.
Instance details Defined in Text.JSON Methods readJSON :: JSValue -> Result JSValue Source # showJSON :: JSValue -> JSValue Source # readJSONs :: JSValue -> Result [JSValue] Source # showJSONs :: [JSValue] -> JSValue Source #

# Wrapper Types

newtype JSString Source #

Strings can be represented a little more efficiently in JSON

Constructors

JSONString |

Fields

- fromJSString :: String

#### Instances

Instances details

IsString JSString Source # |
Instance details Defined in Text.JSON.Types Methods fromString :: String -> JSString Source #
Read JSString Source # |
Instance details Defined in Text.JSON.Types Methods readsPrec :: Int -> ReadS JSString Source # readList :: ReadS [JSString] Source # readPrec :: ReadPrec JSString Source # readListPrec :: ReadPrec [JSString] Source #
Show JSString Source # |
Instance details Defined in Text.JSON.Types Methods showsPrec :: Int -> JSString -> ShowS Source # show :: JSString -> String Source # showList :: [JSString] -> ShowS Source #
Eq JSString Source # |
Instance details Defined in Text.JSON.Types Methods (==) :: JSString -> JSString -> Bool Source # (/=) :: JSString -> JSString -> Bool Source #
Ord JSString Source # |
Instance details Defined in Text.JSON.Types Methods compare :: JSString -> JSString -> Ordering Source # (<) :: JSString -> JSString -> Bool Source # (<=) :: JSString -> JSString -> Bool Source # (>) :: JSString -> JSString -> Bool Source # (>=) :: JSString -> JSString -> Bool Source # max :: JSString -> JSString -> JSString Source # min :: JSString -> JSString -> JSString Source #
JSKey JSString Source # |
Instance details Defined in Text.JSON Methods toJSKey :: JSString -> String Source # fromJSKey :: String -> Maybe JSString Source #
JSON JSString Source # |
Instance details Defined in Text.JSON Methods readJSON :: JSValue -> Result JSString Source # showJSON :: JSString -> JSValue Source # readJSONs :: JSValue -> Result [JSString] Source # showJSONs :: [JSString] -> JSValue Source #

toJSString :: String -> JSString Source #

Turn a Haskell string into a JSON string.

newtype JSObject e Source #

As can association lists

Constructors

JSONObject |

Fields

- fromJSObject :: [(String, e)]

#### Instances

Instances details

Read e => Read (JSObject e) Source # |
Instance details Defined in Text.JSON.Types Methods readsPrec :: Int -> ReadS (JSObject e) Source # readList :: ReadS [JSObject e] Source # readPrec :: ReadPrec (JSObject e) Source # readListPrec :: ReadPrec [JSObject e] Source #
Show e => Show (JSObject e) Source # |
Instance details Defined in Text.JSON.Types Methods showsPrec :: Int -> JSObject e -> ShowS Source # show :: JSObject e -> String Source # showList :: [JSObject e] -> ShowS Source #
Eq e => Eq (JSObject e) Source # |
Instance details Defined in Text.JSON.Types Methods (==) :: JSObject e -> JSObject e -> Bool Source # (/=) :: JSObject e -> JSObject e -> Bool Source #
Ord e => Ord (JSObject e) Source # |

Instance details

Defined in Text.JSON.Types

Methods

compare :: JSObject e -> JSObject e -> Ordering Source #

(<) :: JSObject e -> JSObject e -> Bool Source #

(<=) :: JSObject e -> JSObject e -> Bool Source #

(>) :: JSObject e -> JSObject e -> Bool Source #

(>=) :: JSObject e -> JSObject e -> Bool Source #

max :: JSObject e -> JSObject e -> JSObject e Source #

min :: JSObject e -> JSObject e -> JSObject e Source #

JSON a => JSON (JSObject a) Source # |
Instance details Defined in Text.JSON Methods readJSON :: JSValue -> Result (JSObject a) Source # showJSON :: JSObject a -> JSValue Source # readJSONs :: JSValue -> Result [JSObject a] Source # showJSONs :: [JSObject a] -> JSValue Source #

toJSObject :: [(String, a)] -> JSObject a Source #

Make JSON object out of an association list.

get_field :: JSObject a -> String -> Maybe a Source #

Get the value of a field, if it exist.

set_field :: JSObject a -> String -> a -> JSObject a Source #

Set the value of a field. Previous values are overwritten.