[Lift] Re: lift-json's extract and Mapper

2009-10-05 Thread Joni Freeman
Hi Peter, To select multiple packets you need to first select the objects within the array. Like this: for { JObject(packet) - parse(s) JField(node, JString(node)) - packet JField(dt, JInt(dt)) - packet JField(temp, JDouble(temp)) - packet } yield // construct Packet here Cheers Joni

[Lift] Re: lift-json's extract and Mapper

2009-10-05 Thread Peter Robinett
Thanks, Joni, that works perfectly! Peter On Oct 5, 8:49 am, Joni Freeman freeman.j...@gmail.com wrote: Hi Peter, To select multiple packets you need to first select the objects within the array. Like this: for {   JObject(packet) - parse(s)   JField(node, JString(node)) - packet  

[Lift] Re: lift-json's extract and Mapper

2009-10-04 Thread Joni Freeman
I don't know how hard would it be to add this feature, so I don't know if this is a reasonable request. This would make making JSON API endpoints really easy for me and I hope for other people too. This certainly sounds like a reasonable feature request, I will take a deeper look at it.

[Lift] Re: lift-json's extract and Mapper

2009-10-04 Thread Peter Robinett
Thanks, Joni. I've been playing with just that for comprehension syntax over the weekend. How would I do it if I had multiple packets? { packets: [ { node: 00:1D:C9:00:04:9F, dt: 1254553581405, temp: 27.5 }, { node: 00:1D:C9:00:04:9E, dt: 1254553582405, temp: 24.3

[Lift] Re: lift-json's extract and Mapper

2009-10-03 Thread Kevin Wright
Sounds to me like you want to create yourself a small helper function that can map that structure into your own case class, something like: case class TempReading(node:String, dt:Int, temp:Double) It should be possible to do this as a layer on top of the json parser. So you can go from:

[Lift] Re: lift-json's extract and Mapper

2009-10-03 Thread Kevin Wright
Totally untested, but something like this might work for you: case class TempReading(node:String, dt:Int, temp:Double) object JsonTempReading { def unapply(obj: JObject) : Option[TempReading] { obj match { case JObject(List( JField(node, JString(node)), JField(dt,

[Lift] Re: lift-json's extract and Mapper

2009-10-03 Thread Peter Robinett
Thanks, Kevin. I'm going to poke around with lift-json a bit more but a case class may be the way to go. As for the datetime, it's actually stored as a Long representing a millisecond Unix timestamp. I've considered scala-time but haven't seen the need to switch yet. Peter On Oct 3, 11:13 am,

[Lift] Re: lift-json's extract and Mapper

2009-10-03 Thread Kevin Wright
On Sat, Oct 3, 2009 at 10:43 AM, Peter Robinett pe...@bubblefoundry.com wrote: Thanks, Kevin. I'm going to poke around with lift-json a bit more but a case class may be the way to go. case classes definitely get you some juicy extras, it becomes a lot easier to filter or map a list of

[Lift] Re: lift-json's extract and Mapper

2009-10-03 Thread Peter Robinett
On Oct 3, 12:04 pm, Kevin Wright kev.lee.wri...@googlemail.com wrote: On Sat, Oct 3, 2009 at 10:43 AM, Peter Robinett pe...@bubblefoundry.com wrote: Thanks, Kevin. I'm going to poke around with lift-json a bit more but a case class may be the way to go. case classes definitely get you

[Lift] Re: lift-json's extract and Mapper

2009-10-03 Thread Kevin Wright
On Sat, Oct 3, 2009 at 11:33 AM, Peter Robinett pe...@bubblefoundry.com wrote: On Oct 3, 12:04 pm, Kevin Wright kev.lee.wri...@googlemail.com wrote: On Sat, Oct 3, 2009 at 10:43 AM, Peter Robinett pe...@bubblefoundry.com wrote: Thanks, Kevin. I'm going to poke around with lift-json a