[ https://issues.apache.org/jira/browse/FREEMARKER-90?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16368790#comment-16368790 ]
smforapache commented on FREEMARKER-90: --------------------------------------- Thanks Daniel. I just reproduced this using http://try.freemarker.org/. Please find below. Data model : getProductCategories = {"categories": {"Daily Special": {},"Main Course": {}}} payLoad = {"category" : "Daily Special"} ftl : { "recipient":{ "id":"" }, "message": { "text": "${payLoad.category}", "quick_replies": [ <#assign subcategory_string = "getProductCategories.categories."+"${payLoad.category}"> <#assign subcategories = subcategory_string?eval> <#list subcategories?keys as subcategory> { "payload" : "{\"intent\": \"ordermenu\", \"category\": \"${payLoad.category}\",\"subcategory\": \"${subcategory}\"}", "title":"${subcategory}", "content_type": "text" } <#sep>, </#sep> </#list> ] } } result : Failed to "?eval" string with this error: ---begin-message--- Syntax error in ?eval-ed string in line 1, column 40: Encountered "Special", but was expecting one of: ".." <DOT_DOT_LESS> "..*" ")" ---end-message--- The failing expression: ==> subcategory_string?eval [in nameless template at line 10, column 26] ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign subcategories = subcategory_s... [in nameless template at line 10, column 1] ---- > Unable to parse keys of json having spaces > ------------------------------------------ > > Key: FREEMARKER-90 > URL: https://issues.apache.org/jira/browse/FREEMARKER-90 > Project: Apache Freemarker > Issue Type: Bug > Reporter: smforapache > Priority: Critical > Attachments: getSubCategories.ftl > > > Facing issues while trying to parse JSON having keys with spaces in > freemarkerĀ template. > Sample JSONĀ : > { > "response": { > "categories": { > "Daily Special": {}, > "Main Course": {} > } > } > } > Attached the ftl file used to parse this. > script in ftl which is failing where payLoad.category is Daily Special. > <#assign subcategory_string = "response.categories."+"${payLoad.category}"> > <#assign subcategories = subcategory_string?eval> > Exception : > [WARN ] 2018-02-18 10:07:54.085 [asyncExecutor-3] TemplateBuilder - > TemplateBuilder: Unable to substitute template > freemarker.core._MiscTemplateException: Failed to "?eval" string with this > error: > ---begin-message--- > Syntax error in ?eval-ed string in line 1, column 40: > Encountered "Special", but was expecting one of: > ".." > <DOT_DOT_LESS> > "..*" > ")" > "." > "[" > "(" > "?" > "!" > <TERMINATING_EXCLAM> > "??" > "+" > "-" > "*" > "/" > "%" > "!=" > "=" > "==" > ">=" > <ESCAPED_GTE> > ">" > <ESCAPED_GT> > <LESS_THAN_EQUALS> > <LESS_THAN> > <AND> > <OR> > ---end-message--- > The failing expression: > ==> subcategory_string?eval [in template "TEMPLATE" at line 10, column 26] > ---- > FTL stack trace ("~" means nesting-related): > - Failed at: #assign subcategories = subcategory_s... [in template > "TEMPLATE" at line 10, column 1] > ---- > at > freemarker.core.BuiltInsForStringsMisc$evalBI.calculateResult(BuiltInsForStringsMisc.java:70) > ~[freemarker-2.3.23.jar!/:2.3.23] > at freemarker.core.BuiltInForString._eval(BuiltInForString.java:26) > ~[freemarker-2.3.23.jar!/:2.3.23] > at freemarker.core.Expression.eval(Expression.java:78) > ~[freemarker-2.3.23.jar!/:2.3.23] > at freemarker.core.Assignment.accept(Assignment.java:131) > ~[freemarker-2.3.23.jar!/:2.3.23] > at freemarker.core.Environment.visit(Environment.java:324) > ~[freemarker-2.3.23.jar!/:2.3.23] > at freemarker.core.MixedContent.accept(MixedContent.java:54) > ~[freemarker-2.3.23.jar!/:2.3.23] > at freemarker.core.Environment.visit(Environment.java:324) > ~[freemarker-2.3.23.jar!/:2.3.23] > at freemarker.core.Environment.process(Environment.java:302) > ~[freemarker-2.3.23.jar!/:2.3.23] > at freemarker.template.Template.process(Template.java:325) > ~[freemarker-2.3.23.jar!/:2.3.23] > Is there any way to get out of this issue ? -- This message was sent by Atlassian JIRA (v7.6.3#76005)