object to json string android

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

Also in JavaScript: