'Write newline separated JSON dicts for each value.
We write each dict separately so we don\'t have to hold all of the output
streams in memory. We open and close the JSON array manually with [].
Args:
values: RDF values to export.'

@utils.Synchronized
def WriteValuesToJSONFile(self, values):

    value_counters = {}
    max_post_size = config.CONFIG['BigQuery.max_file_post_size']
    for value in values:
        class_name = value.__class__.__name__
        (output_tracker, created) = self._GetTempOutputFileHandles(class_name)
        value_counters[class_name] = (value_counters.get(class_name, (-1)) + 1)
        if (not ((value_counters[class_name] % max_post_size) // 1000)):
            output_tracker.gzip_filehandle.flush()
            if (os.path.getsize(output_tracker.gzip_filehandle.name) > max_post_size):
                self.Flush()
                value_counters[class_name] = 0
                (output_tracker, created) = self._GetTempOutputFileHandles(class_name)
        if (not output_tracker.schema):
            output_tracker.schema = self.RDFValueToBigQuerySchema(value)
        if created:
            self._WriteJSONValue(output_tracker.gzip_filehandle, value)
        else:
            self._WriteJSONValue(output_tracker.gzip_filehandle, value, delimiter='\n')
    for output_tracker in self.temp_output_trackers.values():
        output_tracker.gzip_filehandle.flush()
