Catch json_encode errors, report error as result