[stringtemplate-interest] Generating JSON using StringTemplate
p_machner at poczta.fm
p_machner at poczta.fm
Thu Nov 17 05:57:42 PST 2011
Udo, this is a good point. I think I'll go this way.Thanks a lot and best regards,Piotr"Udo Borkowski" <Udo.Borkowski at gmx.de> pisze:Hi Piotr,you don't need to add the 'format="…"' in many many places. Just create one template containing the formatted string rendering and use that template instead of the '…' stuff.E.g. create a template "q" (for "quote")q(s) ::= <<<s;format="singleQuote">>>main(user) ::= <<{ firstName: <q(user.firstName)>, lastName: <q(user.lastName)>}>>This will output:{ firstName: 'Joe', lastName: 'O\'Donovan'}Depending on the concrete application I would also consider adding a template to render both the key and value:kv(key, value) ::= <<<key>: <value;format="singleQuote">>>main(user) ::= <<{ <kv("firstName",user.firstName)>, <kv("lastName", user.lastName)>}>>UdoOn 15.11.2011, at 15:20, p_machner at poczta.fm wrote:Thanks a lot for your tip Johan :) I was considering this solution, it should allow me to do what I need but it has one disadvantage - it will clutter up my templates with something like 'format="string"' in many many places and this is something I've wanted to avoid.Any other ideas?Thanks and best regards,Piotr"Johan Stuyts" <j.stuyts at javathinker.com> pisze:Any ideas on how this escaping can be easily achieved?You have to specify the format option in the template, and detect it in the attribute renderer:Regards,Johan_______________________________________________stringtemplate-interest mailing liststringtemplate-interest at antlr.orghttp://www.antlr.org/mailman/listinfo/stringtemplate-interest----------------------------------------------------------------Masz strone www? Dodaj ja do katalogu!Sprawdz >> http://linkint.pl/f2a8a_______________________________________________stringtemplate-interest mailing liststringtemplate-interest at antlr.orghttp://www.antlr.org/mailman/listinfo/stringtemplate-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20111117/e7a10fd0/attachment.html
More information about the stringtemplate-interest
mailing list