Refactored the JSON output streaming.

Review: https://reviews.apache.org/r/24877
Adjustments for new JSON streaming.

Review: https://reviews.apache.org/r/25053