A simple Java utility for minifying JSON code in your Java application.
This library is built for use with Java applications for the purpose of minifying JSON code. This work is an adaptation of JSMin.java written by John Reilly (www.inconspicuous.org) which is itself a translation of jsmin.c written by Douglas Crockford (www.crockford.com).
Minify has a simple utility method for producing minified JSON:
/**
* Minifies the input JSON string.
*
* Takes the input JSON string and deletes the characters which are insignificant to JavaScipt. Comments will
* be removed, tabs will be replaced with spaces, carriage returns will be replaced with line feeds, and most
* spaces and line feeds will be removed. The result will be returned.
*
* @param json The JSON string for which to minify
* @return A minified, yet functionally identical, version of the input JSON string
*/
public String minify(String json)
Note: Minify also has a second utility method for producing minified JSON from a stream of input, if you'd like to work directly with streams.
To use the library, simply instantiate an instance of the Minify class and invoke one of the minify() utility methods:
String minifiedJson = new Minify().minify(unminifiedJson);
- Created by Charles Bihis
- Website: www.whoischarles.com
- E-mail: [email protected]
- Twitter: @charlesbihis
- Adapted from JSMin.java written by John Reilly (www.inconspicuous.org)
- Adapted from jsmin.c written by Douglas Crockford (www.crockford.com).
Permission is hereby granted to use this Java version under the same conditions as the original jsmin.c on which all of these derivatives are based. See the header on Minify.java for more.