I have a Java Property file and there is a KEY as ORDER. So I retrieve the VALUE of that KEY using the getProperty(
You can also use JSONObject class from json.org to this will convert your HashMap to JSON string which is well formatted
Example:
Map map = new HashMap<>();
map.put("myNumber", 100);
map.put("myString", "String");
JSONObject json= new JSONObject(map);
String result= json.toString();
System.out.print(result);
result:
{'myNumber':100, 'myString':'String'}
Your can also get key from it like
System.out.print(json.get("myNumber"));
result:
100