json-response: Refactor encodeJSON.