Remove extra white space
Add helper function to detect if an object has to_json method