* @return a json string
*/
public Appendable format(Object source, Appendable ap) throws IOException {
Context context = new Context();
OutputSource fs;
if (ap instanceof Writer) {
fs = new WriterOutputSource((Writer)ap);
} else if (ap instanceof StringBuilder) {
fs = new StringBuilderOutputSource((StringBuilder)ap);
} else {
fs = new AppendableOutputSource(ap);
}
context.enter('$');
source = preformatInternal(context, source);
formatInternal(context, source, fs);
context.exit();
fs.flush();
return ap;
}