code: def save_offsets(
          cls,
          consumer_offsets_metadata,
          topics_dict,
          json_file,
          groupid,
      ):
          
          # Build consumer-offset data in desired format
          current_consumer_offsets = defaultdict(dict)
          for topic, topic_offsets in six.iteritems(consumer_offsets_metadata):
              for partition_offset in topic_offsets:
                  current_consumer_offsets[topic][partition_offset.partition] = \
                      partition_offset.current
          consumer_offsets_data = {'groupid': groupid, 'offsets': current_consumer_offsets}
  
          cls.write_offsets_to_file(json_file, consumer_offsets_data)
docs: Built offsets for given topic-partitions in required format from current
          offsets metadata and write to given json-file.
  
          :param consumer_offsets_metadata: Fetched consumer offsets from kafka.
          :param topics_dict: Dictionary of topic-partitions.
          :param json_file: Filename to store consumer-offsets.
          :param groupid: Current consumer-group.