| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Text.JSON.Types
Contents
Description
Basic support for working with JSON values.
Synopsis
- data JSValue
- newtype JSString = JSONString {}
- 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
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
| IsString JSValue Source # | |
Defined in Text.JSON.Types Methods fromString :: String -> JSValue Source # | |
| Read JSValue Source # | |
| Show JSValue Source # | |
| Eq JSValue Source # | |
| Ord JSValue Source # | |
| JSON JSValue Source # | To ensure we generate valid JSON, we map Haskell types to JSValue internally, then pretty print that. |
Wrapper Types
Strings can be represented a little more efficiently in JSON
Constructors
| JSONString | |
Fields | |
Instances
| IsString JSString Source # | |
Defined in Text.JSON.Types Methods fromString :: String -> JSString Source # | |
| Read JSString Source # | |
| Show JSString Source # | |
| Eq JSString Source # | |
| Ord JSString Source # | |
Defined in Text.JSON.Types | |
| JSKey JSString Source # | |
| JSON JSString Source # | |
toJSString :: String -> JSString Source #
Turn a Haskell string into a JSON string.
As can association lists
Constructors
| JSONObject | |
Fields
| |
Instances
| Read e => Read (JSObject e) Source # | |
| Show e => Show (JSObject e) Source # | |
| Eq e => Eq (JSObject e) Source # | |
| Ord e => Ord (JSObject e) Source # | |
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 # | |
| JSON a => JSON (JSObject a) Source # | |
toJSObject :: [(String, a)] -> JSObject a Source #
Make JSON object out of an association list.