JSONUtil 1.10.0 released

JSONUtil 1.10.0 has been released. Get it here

Strings which do not contain characters which need to be escaped are now encoded dramatically faster. In my tests with large strings (1024 chars) encoding times were reduced by as much 70-80%. This was accomplished by putting a check at the start to see if there are any characters which need to be escaped and if not then just write out the whole string in one shot instead of iterating over the code points.

If the new string encoding still isn’t fast enough and you know for a fact that your strings do not have any characters which need to be escaped, you can use the new JSONConfig.setFastStrings(true) option (also available with JSONConfigDefaults). This eliminates all checking for escapes and writes the strings out with quotes around them. It’s very fast this way but if you have characters that need to be escaped, it could break your JSON. Use with care.

When iterating over the code points in strings, handling of surrogate pairs, especially bad surrogate pairs has been made more sane and reasonable, though I’m not sure what the correct behavior for bad surrogate pairs really should be. For now, bad surrogates are escaped but kept.

Version 1.9 introduced the “preciseNumbers” option. Unfortunately, the code to handle it slowed down all numbers regardless of whether the option was set or not. That has been fixed and number performance has been further optimized and is now very fast, especially if you don’t use custom number formats or BigDecimal or BigInteger.

There is now a JsonObject convenience class. You can use this in place of maps by adding key-value pairs with its add(Object,Object) method. The add method returns the JsonObject itself so that you can do adds in series like this:

JsonObject myObj = new JSONObject().add("x",3).add("y","some string").add("z",3.14);

JsonObject implements JSONAble so it has its four toJSON() methods available for convenience and it is recognized as such when it is encountered inside other data structures.

If you’re using Java 7 or earlier, download the jars with your Java version number. Otherwise just get the regular jars that don’t have a Java version in their name. They require a minimum of Java 8.

The binaries are also available at the Maven Central Repository