[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 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 >   JField("dt",

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

2009-10-04 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 Chee

[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,

[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. Me

[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 wrote: > > > On Oct 3, 12:04 pm, Kevin Wright > wrote: >> On Sat, Oct 3, 2009 at 10:43 AM, Peter Robinett >> 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 c

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

2009-10-03 Thread Peter Robinett
On Oct 3, 12:04 pm, Kevin Wright wrote: > On Sat, Oct 3, 2009 at 10:43 AM, Peter Robinett > 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

[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 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 readings when compared to th

[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, K

[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 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: