I have a HashMap which I need to parse into JSON:
HashMap<String, Integer> worders = new HashMap<>();
I need to parse it into a JSON array of objects. Current values:
{"and": 100},
{"the": 50}
Needed JSON format:
[
{"word": "and",
"count": 100},
{"word": "the",
"count": 50}
]
I have realised that I need to use a loop to put it into the correct format, but not sure where or how to start.
I have also used the ObjectMapper() to write it as JSON, however, that does not correct the format, thank for help.