Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 471
j3d Avatar asked Jan 04 '15 18:01

j3d


1 Answers

According to the documentation is should be like this:

import play.api.libs.json._

Json.toJson(List("one", "one", "two", "two", "three", "three").distinct)
like image 183
Rado Buransky Avatar answered Oct 19 '22 19:10

Rado Buransky