Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Serialising Haskell values to and from JSON5 values.
Synopsis
- data JSValue
- class JSON5 a where
- data Result a
- encode :: JSON5 a => a -> String
- decode :: JSON5 a => String -> Result a
- encodeStrict :: JSON5 a => a -> String
- decodeStrict :: JSON5 a => String -> Result a
- data JSString
- toJSString :: String -> JSString
- fromJSString :: JSString -> String
- data JSObject a
- toJSObject :: [(String, a)] -> JSObject a
- fromJSObject :: JSObject a -> [(String, a)]
- resultToEither :: Result a -> Either String a
- readJSNull :: GetJSON JSValue
- readJSBool :: GetJSON JSValue
- readJSString :: Char -> GetJSON JSValue
- readJSRational :: GetJSON Rational
- readJSArray :: GetJSON JSValue
- readJSObject :: GetJSON JSValue
- readJSValue :: GetJSON JSValue
- showJSNull :: ShowS
- showJSBool :: Bool -> ShowS
- showJSArray :: [JSValue] -> ShowS
- showJSRational :: Rational -> ShowS
- showJSInfNaN :: Float -> ShowS
- showJSObject :: JSObject JSValue -> ShowS
- showJSValue :: JSValue -> ShowS
- makeObj :: [(String, JSValue)] -> JSValue
- valFromObj :: JSON5 a => String -> JSObject JSValue -> Result a
- class JSKey a where
- encJSDict :: (JSKey a, JSON5 b) => [(a, b)] -> JSValue
- decJSDict :: (JSKey a, JSON5 b) => String -> JSValue -> Result [(a, b)]
JSON5 Types
JSNull | |
JSBool !Bool | |
JSNumber JSNumber | |
JSString JSString | |
JSArray [JSValue] | |
JSObject (JSObject JSValue) |
Instances
Eq JSValue Source # | |
Ord JSValue Source # | |
Read JSValue Source # | |
Show JSValue Source # | |
IsString JSValue Source # | |
Defined in Text.JSON5.Types fromString :: String -> JSValue # | |
JSON5 JSValue Source # | To ensure we generate valid JSON5, we map Haskell types to JSValue internally, then pretty print that. |
Serialization to and from JSValues
The class of types serialisable to and from JSON5
readJSON :: JSValue -> Result a Source #
showJSON :: a -> JSValue Source #
Instances
Encoding and Decoding
A type for parser results
encode :: JSON5 a => a -> String Source #
Encode a Haskell value into a string, in JSON5 format.
This is a superset of JSON5, as types other than Array and Object are allowed at the top level.
decode :: JSON5 a => String -> Result a Source #
Decode a String representing a JSON5 value (either an object, array, bool, number, null)
This is a superset of JSON5, as types other than Array and Object are allowed at the top level.
encodeStrict :: JSON5 a => a -> String Source #
Encode a value as a String in strict JSON format. This follows the spec, and requires all values at the top level to be wrapped in either an Array or Object. JSON5 types to be an Array or Object.
decodeStrict :: JSON5 a => String -> Result a Source #
Decode a String representing a strict JSON value. This follows the spec, and requires top level JSON5 types to be an Array or Object.
Wrapper Types
toJSString :: String -> JSString Source #
fromJSString :: JSString -> String Source #
Instances
Eq a => Eq (JSObject a) Source # | |
Ord a => Ord (JSObject a) Source # | |
Read a => Read (JSObject a) Source # | |
Show a => Show (JSObject a) Source # | |
JSON5 a => JSON5 (JSObject a) Source # | |
toJSObject :: [(String, a)] -> JSObject a Source #
fromJSObject :: JSObject a -> [(String, a)] Source #
Serialization to and from Strings.
Reading JSON5
readJSNull :: GetJSON JSValue Source #
Read the JSON5 null type
readJSBool :: GetJSON JSValue Source #
Read the JSON5 Bool type
readJSRational :: GetJSON Rational Source #
Numbers
Read an Integer or Double in JSON5 format, returning a Rational
readJSArray :: GetJSON JSValue Source #
Objects & Arrays
Read a list in JSON5 format
readJSObject :: GetJSON JSValue Source #
Read an object in JSON5 format
readJSValue :: GetJSON JSValue Source #
Read one of several possible JS types
Writing JSON5
showJSNull :: ShowS Source #
Write the JSON5 null type
showJSBool :: Bool -> ShowS Source #
Write the JSON5 Bool type
showJSArray :: [JSValue] -> ShowS Source #
Show a list in JSON format
showJSRational :: Rational -> ShowS Source #
Show a Rational in JSON5 format
showJSInfNaN :: Float -> ShowS Source #
Show a Infinity or NaN in JSON5 format
showJSValue :: JSValue -> ShowS Source #
Show JSON5 values
Instance helpers
valFromObj :: JSON5 a => String -> JSObject JSValue -> Result a Source #
Pull a value out of a JSON5 object.
Haskell types that can be used as keys in JSON5 objects.