docs: @SuppressWarnings("unchecked")
      public static Object compactJson(Object source) {
          if (source == null) return null;
  
          if (source instanceof List) {
              for (Object item : (List) source) {
                  if (item instanceof List) {
                      compactJson(item);
                  }
                  else if (item instanceof Map) {
                      compactJson(item);
                  }
              }
              ((List) source).removeAll(Collections.singleton(null));
          }
          else if (source instanceof Map) {
              List keysToRemove = new LinkedList();
              for (Object key : ((Map) source).keySet()) {
                  Object value = ((Map)source).get(key);
                  if (value instanceof List) {
                      if (((List) value).size() == 0)
                          keysToRemove.add(key);
                      else {
                          compactJson(value);
                      }
                  } else if (value instanceof Map) {
                      if (((Map) value).size() == 0) {
                          keysToRemove.add(key);
                      } else {
                          compactJson(value);
                      }
                  } else if (value == null) {
                      keysToRemove.add(key);
                  }
              }
              for(Object key: keysToRemove) {
                  ((Map) source).remove(key);
              }
          }
          else {
              throw new UnsupportedOperationException( "Only Map/String and List/Integer types are supported" );
          }
  
          return source;
      }