Forum Discussion

tripp-bishop's avatar
12 years ago

convert JSON to a map in freemarker

Hi guys,

 

Is there a way to convert a JSON object into a map in freemarker without using eval? eval only seems to work for admins and I'm really leary of it anyways as it seems to be a security issue... The incoming data is from a standard user on the site, not a trusted admin. I'm taking a form submit and processing the data and need to iterate over a list of objects. A map/sequence would be ideal for this if I can get the data into the right shape. Any ideas?

 

Cheers,

 

Tripp

1 Reply

  • JakeS's avatar
    JakeS
    Lithium Alumni (Retired)
    12 years ago

    Hi Tripp,

     

    I think you should have access to eval in Freemarker, it's a Freemarker built-in.  As far as security, it will depend how you're eventually using the input, but I don't think that Freemarker eval can be a security issue on its own since it won't do anything to change the Freemarker context.  You could also try using javascript to create the map (there are examples online), although in that case you'll probably want to use parse, not eval.  Obviously you still have to be careful about what you do with the values, but Freemarker eval should be safe on its own to make the hash.

     

    Best,

    Jake Scheps