JSONUtil 1.7 released

JSONUtil 1.7 has been released. Get it here

JSONParser now takes java.io.Reader as an input, which means it takes InputStreamReader, BufferedReader and FileReader which gives you more parsing options. Memory efficiency has been improved by not tokenizing everything before beginning the parsing of tokens. Tokens are read from the input as the parser needs them and discarded when the parser is done with them.

There’s a new class called IndentPadding which when defined and added to your JSONConfig will cause the generated JSON to be formatted with one item per line and indented. This can be useful for debugging but it can also make your JSON a lot bigger. It’s also possible to programmatically set a default IndentPadding in JSONConfigDefaults which will put it in all new JSONConfig objects that are created.

When writing strings or identifiers when escaping bad identifier code points is enabled, Javascript escapes which are illegal in JSON will be unescaped and possibly reescaped legally if needed. These include hex and octal character escapes and \v and '. If useECMA6 is not enabled, then ECMAScript 6 code point escapes will also be unescaped and possibly reescaped legally as needed. This will happen when writing strings even if you don’t enable unescapeWherePossible.

For those that are interested in the source, JSONUtil has had a major refactoring of the code point looping code. A package private inner class named CodePointData has been created to encapsulate the redundant code used by several methods to step through a string of code points. For writeString() and escapeBadIdentifierCodePoints() it also does all of the work of handling escape pass throughs and unescaping Javascript escapes which are illegal in JSON and doing single other creating needed escapes. This has dramatically shortened a few methods and mildly shortened the rest that are using it. Regular expression matches in arbitrary strings are now region limited to improve performance.

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