JsonUtils { public static String minify(String jsonString) { Minify minifier = new Minify(); if (true) { return minifier.minify(jsonString); } boolean in_string = false; boolean in_multiline_comment = false; boolean in_singleline_comment = false; char string_opener = 'x'; final StringBuilder out = new StringBuilder(); for (int i = 0; i < jsonString.length(); i++) { char c = jsonString.charAt(i); String cc = jsonString.substring(i, Math.min(i + 2, jsonString.length())); if (in_string) { if (c == string_opener) { in_string = false; out.append(c); } else if (c == '\\') { out.append(cc); ++i; } else { out.append(c); } } else if (in_singleline_comment) { if (c == '\r' || c == '\n') { in_singleline_comment = false; } } else if (in_multiline_comment) { if (cc.equals("*/")) { in_multiline_comment = false; ++i; } } else if (cc.equals("/*")) { in_multiline_comment = true; ++i; } else if (cc.equals(" in_singleline_comment = true; ++i; } else if (c == '"' || c == '\'') { in_string = true; string_opener = c; out.append(c); } else if (!Character.isWhitespace(c)) { out.append(c); } } return out.toString(); }  static BsonValue unescapeKeys(BsonValue json); static BsonValue escapeKeys(BsonValue json, boolean escapeDots); static List<Optional<BsonValue>> getPropsFromPath(
            BsonValue root,
            String path); static boolean isAncestorPath(final String left, final String right); static Integer countPropsFromPath(BsonValue root, String path); static boolean checkType(Optional<BsonValue> o, String type); static String minify(String jsonString); static BsonValue parse(String json); static String toJson(BsonValue bson); static String toJson(BsonValue bson, JsonMode mode); static String getIdAsString(BsonValue id, boolean quote); static BsonDocument toBsonDocument(Map<String, Object> map); static boolean isUpdateOperator(String key); static boolean containsUpdateOperators(BsonValue json); static boolean containsUpdateOperators(BsonValue json,
            boolean ignoreCurrentDate); static BsonValue unflatten(BsonValue json); static BsonDocument flatten(BsonDocument json, boolean ignoreUpdateOperators);  }
@Test public void testMinify() { String json = "{ '_id' : { '$in' : [1, 20.0, 'id']}}"; String minified = "{'_id':{'$in':[1,20.0,'id']}}"; Assert.assertEquals(minified, JsonUtils.minify(json)); }