wro4j-extensions/src/main/java/ro/isdc/wro/extensions/script/RhinoUtils.java
public static String toJson(final Object object, final boolean indent) {
    final StringBuilder s = new StringBuilder();
    encode(s, object, indent, indent ? 0 : -1);
    return s.toString();
  }
public static String toJson(final Object object, final boolean indent) {
    final StringBuilder s = new StringBuilder();
    encode(s, object, indent, indent ? 0 : -1);
    return s.toString();
  }
public static String toJson ( final Object object , final boolean indent ) { final StringBuilder s = new StringBuilder ( ) ; encode ( s , object , indent , indent ? 0 : - 1 ) ; return s . toString ( ) ; }
Recursively convert from native Rhino to JSON.
<p>
Recognizes JavaScript objects, arrays and primitives.
<p>
Special support for JavaScript dates: converts to {"$date": timestamp} in JSON.
<p>
Special support for MongoDB ObjectId: converts to {"$oid": "objectid"} in JSON.
<p>
Also recognizes JVM types: java.util.Map, java.util.Collection, java.util.Date.

@param object
A Rhino native object
@param indent
Whether to indent the JSON for human readability
@return The JSON string
Recursively convert from native Rhino to JSON . <p > Recognizes JavaScript objects arrays and primitives . <p > Special support for JavaScript dates : converts to { $date : timestamp } in JSON . <p > Special support for MongoDB ObjectId : converts to { $oid : objectid } in JSON . <p > Also recognizes JVM types : java . util . Map java . util . Collection java . util . Date .