Add compare, json encoding, and repr()

Convenience functions
`obj` -> `self`?