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

Copyright(c) Galois, Inc. 2007-2009
LicenseBSD3
MaintainerSigbjorn Finne <sof@galois.com>
Stabilityprovisional
Portabilityportable
Safe HaskellSafe
LanguageHaskell98

Text.JSON.Types

Contents

Description

 

Synopsis

JSON Types

data JSValue #

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

Instances

Eq JSValue # 

Methods

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

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

Ord JSValue # 
Read JSValue # 
Show JSValue # 
JSON JSValue #

To ensure we generate valid JSON, we map Haskell types to JSValue internally, then pretty print that.

Wrapper Types

toJSString :: String -> JSString #

Turn a Haskell string into a JSON string.

newtype JSObject e #

As can association lists

Constructors

JSONObject 

Fields

Instances

Eq e => Eq (JSObject e) # 

Methods

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

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

Ord e => Ord (JSObject e) # 

Methods

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

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

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

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

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

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

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

Read e => Read (JSObject e) # 
Show e => Show (JSObject e) # 

Methods

showsPrec :: Int -> JSObject e -> ShowS #

show :: JSObject e -> String #

showList :: [JSObject e] -> ShowS #

JSON a => JSON (JSObject a) # 

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

Make JSON object out of an association list.

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

Get the value of a field, if it exist.

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

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