Add JsonOut class for serializing to JSON

The same as #3379 except with some basic inheritable interfaces for easy serialization to and from strings and streams, and minus the usage example.