Search code examples
javaarraysjsonliferayfreemarker

How to access json value by key value in freemarker?


Is there any way to access a json value by key value in freemarker? The json looks like this:

{"className":"Lorem Ipsum","classPK":"52293","title":"Test Name"}

I need these values to use them in a method:

localService.method(className, classPK);

I was trying to access them directly with ${json.getData()["classPK"]}. How to do it?


Solution

  • You can use by using ${variableName.key}. In Your case <#assign data="Your JSON Goes here"?eval> then after access using ${data.className}.

    Here Using ?eval on String data which includes JSON ,we convert it to Freemarker littral.

    For more information follow the links:- https://docs.akana.com/ag/processes/process_transform_freemarker.htm https://liferay.dev/blogs/-/blogs/working-with-json-in-freemarker