Added handling of JSON objects and errors