Results in Json Format

I am using Play 2.8 and trying to return error messages in Json format.
I tried
Results.InternalServerError(
Json.obj(“status”->“failed”, “reason”->“Timedout”))
as well as
Results.InternalServerError(
Json.obj(“status”->“failed”, “reason”->“Timedout”).toString)
but the response is coming back as a string instead of json.

How can I return data back as Json ?

Can you post a bit more of your code?

A very trivial endpoint seems to return JSON as expected:

  def sample() =
    Action { implicit request: Request[AnyContent] =>
      Results.InternalServerError(
        Json.obj(
          "one"-> "two",
          "three" -> "four"
        )
      )
    }

I have a simpla call which is very similar to what you described
def sample() =
Action.async { implicit request: Request[AnyContent] =>

Results.InternalServerError(
Json.obj(“status”->“failed”, “reason”->“Timedout”))
)
}
On the client end the response is "“status”:“failed”,“reason”:There is already an account ““status”:“failed”,“reason”:“Timedout””
So the response is a string and not Json… no curly brackets.

Sorry about the response is
“”“status”:“failed”,“reason”: ““status”:“failed”,“reason”:“Timedout”””
Essentially just a string and not a json

I even tried setting
play.http.errorHandler = play.api.http.JsonHttpErrorHandler

in server conf file and did not see and difference.

When I tried the following in console I see
val y = Results.InternalServerError(Json.obj(“status” -> “failed”, “reason” -> “TimedOut”))

y: play.api.mvc.Result = Result(500, TreeMap())

Solved the issue by providing implicit Json reads