Note that this should report an error if $res is empty-ish (e.g. if $result is "{}" or "[]" or "''"). That seems appropriate -- even though $result is technically valid JSON, it's not a valid API response - AFAIK there should always be some response value (like "is_error", "count", "values", etc).