generalize serialize_json so that it takes a Sink as an argument instead of returning a vector