for (Role role : roles) {
JSONObject jrole = new JSONObject();
jrole.element("name", role.getName());
jroles.element(jrole);
JSONArray jpermissions = new JSONArray();
jrole.element("permissions", jpermissions);
for (Permission permission : role.getPermissions()) {
JSONObject jpermission = new JSONObject();
jpermissions.element(jpermission);
jpermission.element("key", permission.getKey());
jpermission.element("value", permission.getValue());