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 .
