[Lift] Re: Typesafe JSON builder?
I've read some stuff about Jorge Ortiz's Json Parser and how its super type safe, i guess you could use that same logic to create your builder (and I would not be surprised if theres something like that laying around in Lift). I hope if there is, someone will point you in the right direction, all I can do is point you to that parser: http://technically.us/git?p=dispatch.git;a=blob;f=src/main/scala/dispatch/Json.scala;h=776da7b6c399d2985dfbed74bd31a197568360f9;hb=HEAD On Jul 9, 10:35 am, Jeppe Nejsum Madsen je...@ingolfs.dk wrote: Hi, Has anyone made a typesafe JSON builder? Many Javascript libraries provides support for extensive customization, usually via a JSON object (eg.http://www.jqplot.com/docs/files/optionsTutorial-txt.html#Options_Tut... It would be nice to generate this from Scala which would then give you type checking, IDE auto completion etc. Lacking concrete implementations, any ideas on the best way to approach this. I've seenhttp://blog.rafaelferreira.net/2008/07/type-safe-builder-pattern-in-s... which looks like a viable (if a bit verbose) approach. /Jeppe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Typesafe JSON builder?
Please take a look on JsObj. But what is your exact use case? ... generate JSON constructs from Scala and send then to browser? Br's, Marius On Jul 9, 8:35 pm, Jeppe Nejsum Madsen je...@ingolfs.dk wrote: Hi, Has anyone made a typesafe JSON builder? Many Javascript libraries provides support for extensive customization, usually via a JSON object (eg.http://www.jqplot.com/docs/files/optionsTutorial-txt.html#Options_Tut... It would be nice to generate this from Scala which would then give you type checking, IDE auto completion etc. Lacking concrete implementations, any ideas on the best way to approach this. I've seenhttp://blog.rafaelferreira.net/2008/07/type-safe-builder-pattern-in-s... which looks like a viable (if a bit verbose) approach. /Jeppe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Typesafe JSON builder?
marius d. marius.dan...@gmail.com writes: Please take a look on JsObj. That's what I'm using now and it's a pain: def generateOptions = JsObj( (title, My title), (series, JsArray(JsObj((Label,MyLabel, (seriesColors, JsArray(#00,#cc)), (axes, JsObj( (xaxis, JsObj( (renderer, JsVar($.jqplot.CategoryAxisRenderer)), (ticks, JsArray(data.flatMap(series = {series.labels.map(v = v.toString)}) : _*)) )), (yaxis, JsObj( (min, 0), (tickOptions, JsObj( (formatString, %d) )) )) )), (seriesDefaults, JsObj( (renderer, JsVar($.jqplot.BarRenderer)), (rendererOptions, JsObj( (barDirection, horizontal), (barPadding, 8), (barMargin,20), (barWidth, 20) )) ))) But what is your exact use case? ... generate JSON constructs from Scala and send then to browser? Yes, I want the above JSON object (which is just a subset of the full capabilities) to be generated in Scala, so I: - will get typechecking - Don't have to remember field names - Can't get autocompletion on valid values for things like - e.g. barDirection /Jeppe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Typesafe JSON builder?
Perhaps consider this other scala JSON lib: http://github.com/jonifreeman/literaljson/tree/master NB: I've not used this, im just adding it for discussion as it might help you. Cheers, Tim On Jul 10, 9:44 am, Jeppe Nejsum Madsen je...@ingolfs.dk wrote: marius d. marius.dan...@gmail.com writes: Please take a look on JsObj. That's what I'm using now and it's a pain: def generateOptions = JsObj( (title, My title), (series, JsArray(JsObj((Label,MyLabel, (seriesColors, JsArray(#00,#cc)), (axes, JsObj( (xaxis, JsObj( (renderer, JsVar($.jqplot.CategoryAxisRenderer)), (ticks, JsArray(data.flatMap(series = {series.labels.map(v = v.toString)}) : _*)) )), (yaxis, JsObj( (min, 0), (tickOptions, JsObj( (formatString, %d) )) )) )), (seriesDefaults, JsObj( (renderer, JsVar($.jqplot.BarRenderer)), (rendererOptions, JsObj( (barDirection, horizontal), (barPadding, 8), (barMargin,20), (barWidth, 20) )) ))) But what is your exact use case? ... generate JSON constructs from Scala and send then to browser? Yes, I want the above JSON object (which is just a subset of the full capabilities) to be generated in Scala, so I: - will get typechecking - Don't have to remember field names - Can't get autocompletion on valid values for things like - e.g. barDirection /Jeppe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Typesafe JSON builder?
On Fri, Jul 10, 2009 at 1:44 AM, Jeppe Nejsum Madsen je...@ingolfs.dkwrote: marius d. marius.dan...@gmail.com writes: Please take a look on JsObj. That's what I'm using now and it's a pain: def generateOptions = JsObj( (title, My title), (series, JsArray(JsObj((Label,MyLabel, (seriesColors, JsArray(#00,#cc)), (axes, JsObj( (xaxis, JsObj( (renderer, JsVar($.jqplot.CategoryAxisRenderer)), (ticks, JsArray(data.flatMap(series = {series.labels.map(v = v.toString)}) : _*)) )), (yaxis, JsObj( (min, 0), (tickOptions, JsObj( (formatString, %d) )) )) )), (seriesDefaults, JsObj( (renderer, JsVar($.jqplot.BarRenderer)), (rendererOptions, JsObj( (barDirection, horizontal), (barPadding, 8), (barMargin,20), (barWidth, 20) )) ))) Looks like Lisp... :-) In all seriousness, one of the pieces of Goat Rodeo (http://goatrodeo.organd Goat Rodeo will become part of Lift once GR is stable) is objects that will know how to serialize themselves as JSON. So, you'll get type safety and bi-direction serialization. In the mean time, I think Marius has some stuff in Record that also does bi-directional JSON. But what is your exact use case? ... generate JSON constructs from Scala and send then to browser? Yes, I want the above JSON object (which is just a subset of the full capabilities) to be generated in Scala, so I: - will get typechecking - Don't have to remember field names - Can't get autocompletion on valid values for things like - e.g. barDirection /Jeppe -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Typesafe JSON builder?
On Jul 10, 6:32 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Fri, Jul 10, 2009 at 1:44 AM, Jeppe Nejsum Madsen je...@ingolfs.dkwrote: marius d. marius.dan...@gmail.com writes: Please take a look on JsObj. That's what I'm using now and it's a pain: def generateOptions = JsObj( (title, My title), (series, JsArray(JsObj((Label,MyLabel, (seriesColors, JsArray(#00,#cc)), (axes, JsObj( (xaxis, JsObj( (renderer, JsVar($.jqplot.CategoryAxisRenderer)), (ticks, JsArray(data.flatMap(series = {series.labels.map(v = v.toString)}) : _*)) )), (yaxis, JsObj( (min, 0), (tickOptions, JsObj( (formatString, %d) )) )) )), (seriesDefaults, JsObj( (renderer, JsVar($.jqplot.BarRenderer)), (rendererOptions, JsObj( (barDirection, horizontal), (barPadding, 8), (barMargin,20), (barWidth, 20) )) ))) Looks like Lisp... :-) In all seriousness, one of the pieces of Goat Rodeo (http://goatrodeo.organdGoat Rodeo will become part of Lift once GR is stable) is objects that will know how to serialize themselves as JSON. So, you'll get type safety and bi-direction serialization. In the mean time, I think Marius has some stuff in Record that also does bi-directional JSON. Correct Dave.Guys please see Record#asJson and Record#fromJSON But what is your exact use case? ... generate JSON constructs from Scala and send then to browser? Yes, I want the above JSON object (which is just a subset of the full capabilities) to be generated in Scala, so I: - will get typechecking - Don't have to remember field names - Can't get autocompletion on valid values for things like - e.g. barDirection /Jeppe -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---