convert hashmap into json

JavaScript
Gson gson = new Gson(); 
String json = gson.toJson(myObject); 
Source

Also in JavaScript: