Add compare, json encoding, and repr()

Convenience functions
It's not a method in the class, just an isolated function.