Encode proper JSON objects when body is empty

PHP's json encoder will encode an empty array object as "[]",
which is not valid JSON.  This fix manually converts the "[]"
to a "{}", which is a valid, empty JSON object.

Note: We cannot use FORCE_JSON_OBJECT with json_encode,
since that will butcher real arrays inside the object.