code: public static JSONObject toJSON(Attributes attributes) {
          JSONObject res = new JSONObject();
          JSONObject vms = new JSONObject();
          JSONObject nodes = new JSONObject();
          for (Element e : attributes.getDefined()) {
              JSONObject el = new JSONObject();
              for (String k : attributes.getKeys(e)) {
                  el.put(k, attributes.get(e, k));
              }
              if (e instanceof VM) {
                  vms.put(Integer.toString(e.id()), el);
              } else {
                  nodes.put(Integer.toString(e.id()), el);
              }
          }
          res.put("vms", vms);
          res.put("nodes", nodes);
          return res;
      }
docs: Serialise attributes.
  @param attributes the attributes
  @return the resulting encoded attributes