[ https://issues.apache.org/jira/browse/FREEMARKER-90?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16371350#comment-16371350 ]
smforapache edited comment on FREEMARKER-90 at 2/21/18 1:16 PM: ---------------------------------------------------------------- Thanks Daniel. This is working . <#assign subcategories = getProductCategories.categories[payLoad.category]> was (Author: smforapache): Thanks Daniel. That's the point. Don't we have a way to get the values from a json key having spaces? > 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)