RJson-0.2: A reflective JSON serializer/parser.Source codeContentsIndex
Text.RJson
Synopsis
class TranslateField a where
translateField :: a -> String -> String
data TranslateFieldD a
translateField :: TranslateField a => a -> String -> String
class ToJson a where
toJson :: a -> JsonData
exclude :: a -> String -> Bool
arrayPrepend :: a -> [JsonData]
arrayAppend :: a -> [JsonData]
objectExtras :: a -> [(String, JsonData)]
data ToJsonD a
toJson :: ToJson a => a -> JsonData
exclude :: ToJson a => a -> String -> Bool
arrayPrepend :: ToJson a => a -> [JsonData]
arrayAppend :: ToJson a => a -> [JsonData]
objectExtras :: ToJson a => a -> [(String, JsonData)]
genericToJson :: (Data ToJsonD a, ToJson a, TranslateField a) => a -> JsonData
data JsonData
= JDString String
| JDNumber Double
| JDArray [JsonData]
| JDBool Bool
| JDObject (Map String JsonData)
class FromJson a where
objectDefaults :: a -> Map String JsonData
data FromJsonD a
objectDefaults :: FromJson a => a -> Map String JsonData
parseJsonString :: String -> Either String JsonData
parseJsonByteString :: ByteString -> Either String JsonData
fromJsonString :: FromJson a => a -> String -> Either String a
fromJsonByteString :: FromJson a => a -> ByteString -> Either String a
genericFromJson :: (Data FromJsonD a, Data TranslateFieldD a) => a -> JsonData -> Either String a
toJsonString :: ToJson a => a -> String
data Union a b = Union a b
type Union3 a b c = Union (Union a b) c
type Union4 a b c d = Union (Union3 a b c) d
type Union5 a b c d e = Union (Union4 a b c d) e
type Union6 a b c d e f = Union (Union5 a b c d e) f
type Union7 a b c d e f g = Union (Union6 a b c d e f) g
type Union8 a b c d e f g h = Union (Union7 a b c d e f g) h
type Union9 a b c d e f g h i = Union (Union8 a b c d e f g h) i
type Union10 a b c d e f g h i j = Union (Union9 a b c d e f g h i) j
Documentation
class TranslateField a whereSource
Methods
translateField :: a -> String -> StringSource
By default, Haskell record field names are converted into JSON object field names by stripping any initial underscores. Specialize this method to define a different behavior.
data TranslateFieldD a Source
show/hide Instances
translateField :: TranslateField a => a -> String -> StringSource
By default, Haskell record field names are converted into JSON object field names by stripping any initial underscores. Specialize this method to define a different behavior.
class ToJson a whereSource

Removes initial underscores from a string.

New instances can be added to this class to customize JSON serialization.

Methods
toJson :: a -> JsonDataSource
exclude :: a -> String -> BoolSource
You can specialize this method to prevent fields from being serialized. The method should return a list of the Haskell names of the fields to be excluded.
arrayPrepend :: a -> [JsonData]Source
Types that will be converted to JSON arrays can override this method to specify additional elements to be prepended to the array.
arrayAppend :: a -> [JsonData]Source
Types that will be converted to JSON arrays can override this method to specify additional elements to be appended to the array.
objectExtras :: a -> [(String, JsonData)]Source
Types that will be converted to JSON objects can override this method to specify additional fields of the object.
show/hide Instances
data ToJsonD a Source
show/hide Instances
toJson :: ToJson a => a -> JsonDataSource
exclude :: ToJson a => a -> String -> BoolSource
You can specialize this method to prevent fields from being serialized. The method should return a list of the Haskell names of the fields to be excluded.
arrayPrepend :: ToJson a => a -> [JsonData]Source
Types that will be converted to JSON arrays can override this method to specify additional elements to be prepended to the array.
arrayAppend :: ToJson a => a -> [JsonData]Source
Types that will be converted to JSON arrays can override this method to specify additional elements to be appended to the array.
objectExtras :: ToJson a => a -> [(String, JsonData)]Source
Types that will be converted to JSON objects can override this method to specify additional fields of the object.
genericToJson :: (Data ToJsonD a, ToJson a, TranslateField a) => a -> JsonDataSource
This is the implementation of toJson for the generic instance declaration, but it's useful to be able to use the same implentation for other instance declarations which override the default implementation of exclude.
data JsonData Source
A Haskell representation of a JSON data structure.
Constructors
JDString String
JDNumber Double
JDArray [JsonData]
JDBool Bool
JDObject (Map String JsonData)
show/hide Instances
class FromJson a whereSource
Methods
objectDefaults :: a -> Map String JsonDataSource
In order to specify default values for required fields of a JSON object, specialize this method in the instance definition for the relevant datatype.
show/hide Instances
data FromJsonD a Source
show/hide Instances
objectDefaults :: FromJson a => a -> Map String JsonDataSource
In order to specify default values for required fields of a JSON object, specialize this method in the instance definition for the relevant datatype.
parseJsonString :: String -> Either String JsonDataSource
Converts a String (interpreted as a true unicode String) to an instance of JsonData.
parseJsonByteString :: ByteString -> Either String JsonDataSource
Converts a ByteString to an instance of JsonData (unicode encoding is detected automatically).
fromJsonString :: FromJson a => a -> String -> Either String aSource
Converts a JSON String (interpreted as a true unicode string) to a value of the type given by the first (dummy) argument.
fromJsonByteString :: FromJson a => a -> ByteString -> Either String aSource
Converts a JSON ByteString (with unicode encoding automatically detected) to a value of the type given by the first (dummy) argument.
genericFromJson :: (Data FromJsonD a, Data TranslateFieldD a) => a -> JsonData -> Either String aSource
toJsonString :: ToJson a => a -> StringSource
Converts a value to an ASCII-only JSON String.
data Union a b Source
Use this for merging two or more records together. Sensible instances of FromJson and ToJson are already defined for this type.
Constructors
Union a b
show/hide Instances
(Show a, Show b) => Show (Union a b)
(FromJson a, FromJson b) => FromJson (Union a b)
(ToJson a, ToJson b) => ToJson (Union a b)
type Union3 a b c = Union (Union a b) cSource
Nested Unions are left-branching by convention (since this is what you get by using the constructor as an infix operator).
type Union4 a b c d = Union (Union3 a b c) dSource
type Union5 a b c d e = Union (Union4 a b c d) eSource
type Union6 a b c d e f = Union (Union5 a b c d e) fSource
type Union7 a b c d e f g = Union (Union6 a b c d e f) gSource
type Union8 a b c d e f g h = Union (Union7 a b c d e f g) hSource
type Union9 a b c d e f g h i = Union (Union8 a b c d e f g h) iSource
type Union10 a b c d e f g h i j = Union (Union9 a b c d e f g h i) jSource
Produced by Haddock version 2.1.0