David Schuler
David Schuler

Reputation: 1031

Scala: Zip two lists into json array format

I have two lists that look like this:

List("key1", "key2")
List("val1", "val2")

I'm trying to get it into this JSON-like format:

[{"key1":"val1"},{"key2","val2"}]

Right now, this is what I'm using:

val output = List(attrKeys.zip(attrValues).toMap)

But it gives me this:

[{"key1":"val1","key2":"val2"}]

How do I get this into a list of separate map objects?

Upvotes: 0

Views: 203

Answers (1)

Joe K
Joe K

Reputation: 18434

attrKeys.zip(attrValues).map(Map(_))

Upvotes: 1

Related Questions