sharkbait
sharkbait

Reputation: 3040

MutableList to JSON in Scala

I have a MutableList builded with a ListBuilder in this way:

Vector("MM_2015_2_EC_13,MM_2015_2_EC_19,.........)

I want to retrieve a JSON like this:

{"ec":
  ["MM_2015_2_EC_13",
  "MM_2015_2_EC_19",
  "MM_2015_2_EC_23",
  "MM_2015_2_EC_29",
  "MM_2015_2_EC_43",
  "MM_2015_2_EC_53",
  "MM_2015_2_EC_59",
  "MM_2015_2_EC_62",
  "MM_2015_2_EC_63",
  "MM_2015_2_EC_64",
  "MM_2015_2_EC_69",
  "MM_2015_2_EC_73",
  "MM_2015_2_EC_75",
  "MM_2015_2_EC_76",
  "MM_2015_2_EC_78",
  "MM_2015_2_EC_88",
  "MM_2015_2_EC_93",
  "MM_2015_2_EC_96",
  "MM_2015_2_EC_98",
  "MM_2015_2_EC_99"],
"pos":
      ["MM_PS_1000123018"],
"yearSeason":
      "2015_2",
"orderType":"2B"}

Sorry, I'm new on Scala and I'm not able to resolve this problem.

Upvotes: 1

Views: 198

Answers (1)

John
John

Reputation: 5364

With the play.api.libs.json library (see play doc), you can do:

JsArray(Vector(...).map{v=>
  JsString(v)
})

(Not tested)

Upvotes: 1

Related Questions