User Answers

The Write obj.%ToJSON() writes to the TCP stream of the HTTP Response, the headers are written before the body.

You' have to call the ReportHttpStatusCode first (which is nothing more then:  Set %response.Status=HttpStatus) and then write the body.