fields-json-0.1: Abusing monadic syntax JSON objects generation.




Abusing monadic do notation library for generating JSON object. Hard-binded to json package from hackage. Main ideas

  • Overloaded function field, that may set values of fields of different types - Bool, Int, String, lists etc.
  • Internal IO - value of the field can be IO a, is we know how to put a into JSON. That means that there is no need to do prebinding
  • Compositionality - value of field can also be fields. Easy to do embeded objects
  • Monadic notation - it really looks nicer then composition with . or some magic combinator
 json $ do
     field "a" "a"
     field "b" [1,2,3]
     field "c" $ do
         field "x" True
         field "y" False

Will generate json object {a : a, b: [1,2,3], c: {x: true, y : false}}



json :: JSFields -> IO JSValueSource

Function for changing JSFields into real JSON object

class JSField a whereSource

The JSField class instances are object that in some sence can be interpreted as value of JSON object fields. To derive new instances use existing instances since internal structure JSFields is hidden.


field :: String -> a -> JSFieldsSource


ToJSON a => JSField a 
JSField JSFields 
JSField [JSFields] 
ToJSON a => JSField (IO a)