I receive from another program Map with string representation of elements:
Map<String,String> properties = new HashMap<String,String>() {{
put("news[0].title", "Title 1");
put("news[0].body", "Body 1");
put("news[1].title", "Title 2");
put("news[1].body", "Body 2");
}};
I need to render it into freemarker-template. In question
freemarker-flat-structure-of-passing-parameters-transfer-to-array-of-objects
we decided that it is impossible to parse this kind of values in freemarker. But freemarker can eval json.
So I need to know how to transform this map into objects or json. I need something like that:
{
"news": [
{"title": "Title1", "body": "Body1"},
{"title": "Title2", "body": "Body2"}
]
}
Names of parameters in map are unknown, not exactly "news", not exactly "title" and "body", I don't know. May be there are some libraries for such purposes?