Package com.google.json
Class EvalMinifier
- java.lang.Object
-
- com.google.json.EvalMinifier
-
public final class EvalMinifier extends Object
Given a string of valid JSON that is going to be parsed via Javascript'sevalbuiltin, tries to reduce the number of bytes sent over the wire by turning it into a Javascript expression that pools constants.
-
-
Constructor Summary
Constructors Constructor Description EvalMinifier()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringminify(String jsonish)Renders JSON-like content safe for use with Javascripteval.static Stringminify(String jsonish, int maximumNestingDepth)Same asminify(String), but allows to set custom maximum nesting depth.
-
-
-
Method Detail
-
minify
public static String minify(String jsonish)
Renders JSON-like content safe for use with Javascripteval.The output is a Javascript expression, not a statement, so if it contains an object (
{properties}) then it still needs to be wrapped in parentheses before being passed toevalas viaeval('(' + s + ')')oreval('0,' + s).- Parameters:
jsonish- a string of JSON-like content as defined byJsonSanitizer.- Returns:
- a valid Javascript expression that has no free variables and whose
execution will have no side-effects, and which can be embedded safely in
an HTML
<script></script>element or inside an XML<![CDATA[...]]>section.
-
minify
public static String minify(String jsonish, int maximumNestingDepth)
Same asminify(String), but allows to set custom maximum nesting depth.- Parameters:
jsonish- a string of JSON-like content as defined byJsonSanitizer.maximumNestingDepth- the maximum nesting depth for theJsonSanitizer- Returns:
- see
minify(String)
-
-