ruby to_json implementation