- class TranslateField a where
- translateField :: a -> String -> String
- data TranslateFieldD a
- class ToJson a where
- toJson :: a -> JsonData
- exclude :: a -> String -> Bool
- arrayPrepend :: a -> [JsonData]
- arrayAppend :: a -> [JsonData]
- objectExtras :: a -> [(String, JsonData)]
- data ToJsonD a
- genericToJson :: (Data ToJsonD a, ToJson a, TranslateField a) => a -> JsonData
- data JsonData
- class FromJson a where
- objectDefaults :: a -> Map String JsonData
- data FromJsonD a
- 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
- stripInitialUnderscores :: [Char] -> [Char]
- 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
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 => TranslateField a | Removes initial underscores from a string. |
data TranslateFieldD a Source
TranslateField t => Sat (TranslateFieldD t) |
New instances can be added to this class to customize JSON serialization.
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.
genericToJson :: (Data ToJsonD a, ToJson a, TranslateField a) => a -> JsonDataSource
A Haskell representation of a JSON data structure.
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.
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
stripInitialUnderscores :: [Char] -> [Char]Source
toJsonString :: ToJson a => a -> StringSource
Converts a value to an ASCII-only JSON String.
Use this for merging two or more records together. Sensible instances of FromJson and ToJson are already defined for this type.
Union a b |