Changed JSON serialization to use stream instead of string.