Reputation: 16440
How do I return a list as a json response?
So say querying /list?id=123 returns
["a", "b", "c"]
Upvotes: 1
Views: 336
Reputation: 10236
Just return in in your RestHelper
, like this:
case Get("test" :: Nil, req) =>
JArray(List(JString("1"), JString("2"))): LiftResponse
Normally, of course, you don't inline the JSON but take it out of a database, or create it with some DSL. (Examples: https://github.com/lift/framework/tree/master/core/json )
Upvotes: 1
Reputation: 7848
The net.liftweb.json
package has what you are looking for. The following snippet should help you get a JSON object that can be returned and converted into a response:
implicit val formats = DefaultFormats
val list = //create list
Extraction.decompose(list)
Upvotes: 1