toJSON support

@corinnekrych added toJSON support plus tests and refactored our existing model for clarity 

let me know what u think