j3d
j3d

Reputation: 9734

Play Framework: How to convert a List to a JsArray

Given the following List...

val list = List("one", "one", "two", "two", "three", "three")

... how do I convert it to a JsArray like this?

["one", "two", "three"]

As you can see, I also need to drop duplicates.

Upvotes: 6

Views: 4415

Answers (1)

Rado Buransky
Rado Buransky

Reputation: 3294

According to the documentation is should be like this:

import play.api.libs.json._

Json.toJson(List("one", "one", "two", "two", "three", "three").distinct)

Upvotes: 8

Related Questions