More reliable handling of JSON messages in a stream.

Also handle arrays of JSON objects instead of just JSON objects.