This is a small, straightforward patch that I'd love to see merged:
It's all pretty self-explanatory, it basically just ports a useful option from to_xml to to_json, making their interfaces more compatible with each other. Feedback would be greatly appreciated.
Thanks, James