Made object_to_json() much more fault tolerant