0
<#assign test='{ "apple": 5, "banana": {"kiwi": 15 }}'?eval>

I need to extract banana object , tried like below but it's getting error out.

${test.banana}

Error For "${...}" content: Expected a string or something automatically convertible to string (number, date or boolean), or "template output" , but this has evaluated to an

extended_hash (wrapper: f.c.HashLiteral$SequenceHash):
==> test.banana  [in nameless template at line 2, column 3]

FTL stack trace ("~" means nesting-related):
    - Failed at: ${test.banana}  [in nameless template at line 2, colum

1 Answer 1

3

These are the ways you can access. Input

    <#assign test = { "apple": "5", "banana": {"kiwi": 15 }} >

Directly access your key and display the value. (if you know the key)

    ${test.banana.kiwi}

Dynamically list the keys

    <#list test.banana?keys as k>
    ${k}
    </#list>

Dynamically list the values

    <#list test.banana?values as v>
    ${v}
    </#list>

Dynamically list the keys and values

    <#list test.banana as k,v >
    ${k}: ${v}
    </#list>

I hope you can access the banana json in any of the 3 ways said above and achieve your objective.

Reference: https://freemarker.apache.org/docs/ref_builtins_hash.html and https://freemarker.apache.org/docs/ref_directive_list.html#ref.directive.list

Tested in https://try.freemarker.apache.org/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.