Randomize
Randomize

Reputation: 9103

Scala-Spray: How to merge JsArray elements

I have two JsArrays representing these two json feeds:

[{
  "value1":"foo",
  "value2":"bar"
}, {...}]

[{
  "value3":"foo2",
  "value4":"bar2"
}, {...}]

How can I merge only the first element of each one to get:

{
  "value1":"foo",
  "value2":"bar",
  "value3":"foo2",
  "value4":"bar2"
}

using spray.json ?

Upvotes: 1

Views: 737

Answers (1)

Ian
Ian

Reputation: 1

(array1.convertTo[Map[String,JsValue]] ++ array2.convertTo[Map[String,JsValue]]).toJson.asJsArray

Assuming array1 and array2 are JsArray

Upvotes: 0

Related Questions