Search code examples
jsonfreemarker

Extracting dynamic values from JSON using Freemarker


I want to extract value dynamically using freemarker from JSON. Let say this is my input :

{"ABC" : {
   "DEF" : "someValue",
   "GHF" : "someValue2"
   }
}

This results in a value ${ABC.DEF} => someValue

The problem I am in isDEF or GHF comes dynamically.

Example :- If input it DEF I want to extract ${ABC.DEF} and if input is GHF I want to extract ${ABC.GHFF}

May anyone advise me that how using freemarker and getting dynamic input I can extract the value.


Solution

  • I guess you want ${ABC[key]}, where key is a variable whose value is either "DEF" or "GHF".