Gson write json to file

Java
Gson gson = new Gson();
gson.toJson(Object, FileWriter(filePath))
Source

Also in Java: