RJson-0.1: A reflective JSON serializer/parser.

Text.RJson

Synopsis

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.

Instances

Data TranslateFieldD a => TranslateField a

Removes initial underscores from a string.

class ToJson a whereSource

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.

Instances

ToJson Bool 
ToJson Char 
ToJson Double 
ToJson Int 
ToJson Integer 
(Data ToJsonD t, TranslateField t) => ToJson t 
(Typeable a, ToJson a) => ToJson [a] 
Integral a => ToJson (Ratio a) 
(ToJson a, ToJson b) => ToJson (a, b) 
(Typeable a, ToJson a, Ix i) => ToJson (Array i a) 
ToJson a => ToJson (Map String a) 
(ToJson a, ToJson b) => ToJson (Union a b) 
(ToJson a, ToJson b, ToJson c) => ToJson (a, b, c) 
(ToJson a, ToJson b, ToJson c, ToJson d) => ToJson (a, b, c, d) 
(ToJson a, ToJson b, ToJson c, ToJson d, ToJson e) => ToJson (a, b, c, d, e) 
(ToJson a, ToJson b, ToJson c, ToJson d, ToJson e, ToJson f) => ToJson (a, b, c, d, e, f) 
(ToJson a, ToJson b, ToJson c, ToJson d, ToJson e, ToJson f, ToJson g) => ToJson (a, b, c, d, e, f, g) 
(ToJson a, ToJson b, ToJson c, ToJson d, ToJson e, ToJson f, ToJson g, ToJson h) => ToJson (a, b, c, d, e, f, g, h) 
(ToJson a, ToJson b, ToJson c, ToJson d, ToJson e, ToJson f, ToJson g, ToJson h, ToJson i) => ToJson (a, b, c, d, e, f, g, h, i) 
(ToJson a, ToJson b, ToJson c, ToJson d, ToJson e, ToJson f, ToJson g, ToJson h, ToJson i, ToJson j) => ToJson (a, b, c, d, e, f, g, h, i, j) 

data ToJsonD a Source

Instances

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.

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.

Instances

FromJson Bool 
FromJson Char 
FromJson Double 
FromJson Int 
FromJson Integer 
Data FromJsonD t => FromJson t 
FromJson a => FromJson [a] 
Integral a => FromJson (Ratio a) 
(FromJson a, FromJson b) => FromJson (a, b) 
(FromJson a, FromJson b) => FromJson (Union a b) 
(FromJson a, FromJson b, FromJson c) => FromJson (a, b, c) 
(FromJson a, FromJson b, FromJson c, FromJson d) => FromJson (a, b, c, d) 
(FromJson a, FromJson b, FromJson c, FromJson d, FromJson e) => FromJson (a, b, c, d, e) 
(FromJson a, FromJson b, FromJson c, FromJson d, FromJson e, FromJson f) => FromJson (a, b, c, d, e, f) 
(FromJson a, FromJson b, FromJson c, FromJson d, FromJson e, FromJson f, FromJson g) => FromJson (a, b, c, d, e, f, g) 
(FromJson a, FromJson b, FromJson c, FromJson d, FromJson e, FromJson f, FromJson g, FromJson h) => FromJson (a, b, c, d, e, f, g, h) 
(FromJson a, FromJson b, FromJson c, FromJson d, FromJson e, FromJson f, FromJson g, FromJson h, FromJson i) => FromJson (a, b, c, d, e, f, g, h, i) 
(FromJson a, FromJson b, FromJson c, FromJson d, FromJson e, FromJson f, FromJson g, FromJson h, FromJson i, FromJson j) => FromJson (a, b, c, d, e, f, g, h, i, j) 

data FromJsonD a Source

Instances

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.

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 

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