class_docstr: A class to store counterfactual examples for one or more inputs
  and feature importance scores.
  
  :param cf_examples_list: A list of CounterfactualExamples instances
  :param local_importance: List of estimated local importance scores. The
      size of the list is the number of input instances, each containing
      feature importance scores for that input.
  :param summary_importance: Estimated global feature importance scores
      based on the input set of CounterfactualExamples instances
docstr: Serialize Explanations object to json.
          
docstr_tok: ["Serialize","Explanations","object","to","json","."]
code: def to_json(self):
      """Serialize Explanations object to json."""
      serialization_version = self.metadata["version"]
      if serialization_version == _SchemaVersions.V1:
          cf_examples_str_list = []
          for cf_examples in self.cf_examples_list:
              cf_examples_str = cf_examples.to_json(
                  serialization_version=serialization_version
              )
              cf_examples_str_list.append(cf_examples_str)
          entire_dict = {
              _CounterfactualExpV1SchemaConstants.CF_EXAMPLES_LIST: cf_examples_str_list,
              _CounterfactualExpV1SchemaConstants.LOCAL_IMPORTANCE: self.local_importance,
              _CounterfactualExpV1SchemaConstants.SUMMARY_IMPORTANCE: self.summary_importance,
              _CounterfactualExpV1SchemaConstants.METADATA: self.metadata,
          }
          CounterfactualExplanations._check_cf_exp_output_against_json_schema(
              entire_dict, version=serialization_version
          )
          return json.dumps(entire_dict)
      elif serialization_version == _SchemaVersions.V2:
          combined_test_instance_list = []
          combined_final_cfs_list = []
          data_interface = None
          feature_names = None
          feature_names_including_target = None
          model_type = None
          desired_class = None
          desired_range = None
          for cf_examples in self.cf_examples_list:
              cf_examples_str = cf_examples.to_json(
                  serialization_version=serialization_version
              )
              # We need to load the json again since we need to decompose the
              # counterfactual example into different schema fields
              serialized_cf_examples = json.loads(cf_examples_str)
              combined_test_instance_list.append(
                  serialized_cf_examples[
                      _DiverseCFV2SchemaConstants.TEST_INSTANCE_LIST
                  ]
              )
              combined_final_cfs_list.append(
                  serialized_cf_examples[
                      _DiverseCFV2SchemaConstants.FINAL_CFS_LIST
                  ]
              )
              data_interface = serialized_cf_examples[
                  _DiverseCFV2SchemaConstants.DATA_INTERFACE
              ]
              feature_names = serialized_cf_examples[
                  _DiverseCFV2SchemaConstants.FEATURE_NAMES
              ]
              feature_names_including_target = serialized_cf_examples[
                  _DiverseCFV2SchemaConstants.FEATURE_NAMES_INCLUDING_TARGET
              ]
              model_type = serialized_cf_examples[
                  _DiverseCFV2SchemaConstants.MODEL_TYPE
              ]
              desired_class = serialized_cf_examples[
                  _DiverseCFV2SchemaConstants.DESIRED_CLASS
              ]
              desired_range = serialized_cf_examples[
                  _DiverseCFV2SchemaConstants.DESIRED_RANGE
              ]
  
          local_importance_matrix = None
          if self.local_importance is not None:
              local_importance_matrix = []
              for local_importance_dict in self.local_importance:
                  local_importance_list = []
                  for feature_name in feature_names:
                      local_importance_list.append(
                          local_importance_dict.get(feature_name)
                      )
                  local_importance_matrix.append(local_importance_list)
  
          summary_importance_list = None
          if self.summary_importance is not None:
              summary_importance_list = []
              for feature_name in feature_names:
                  summary_importance_list.append(
                      self.summary_importance.get(feature_name)
                  )
  
          entire_dict = {
              _CounterfactualExpV2SchemaConstants.TEST_DATA: combined_test_instance_list,
              _CounterfactualExpV2SchemaConstants.CFS_LIST: combined_final_cfs_list,
              _CounterfactualExpV2SchemaConstants.LOCAL_IMPORTANCE: local_importance_matrix,
              _CounterfactualExpV2SchemaConstants.SUMMARY_IMPORTANCE: summary_importance_list,
              _CounterfactualExpV2SchemaConstants.DATA_INTERFACE: data_interface,
              _CounterfactualExpV2SchemaConstants.FEATURE_NAMES: feature_names,
              _CounterfactualExpV2SchemaConstants.FEATURE_NAMES_INCLUDING_TARGET: feature_names_including_target,
              _CounterfactualExpV2SchemaConstants.MODEL_TYPE: model_type,
              _CounterfactualExpV2SchemaConstants.DESIRED_CLASS: desired_class,
              _CounterfactualExpV2SchemaConstants.DESIRED_RANGE: desired_range,
              _CounterfactualExpV1SchemaConstants.METADATA: self.metadata,
          }
          CounterfactualExplanations._check_cf_exp_output_against_json_schema(
              entire_dict, version=serialization_version
          )
          return json.dumps(entire_dict)
      else:
          raise UserConfigValidationException(
              "Unsupported serialization version {}".format(
                  serialization_version
              )
          )
  
imports: import json
  import os
  import jsonschema
  from raiutils.exceptions import UserConfigValidationException
  from dice_ml.constants import _SchemaVersions
  from dice_ml.diverse_counterfactuals import CounterfactualExamples, _DiverseCFV2SchemaConstants
label_desc: Use image node_id 10 for calling the CounterfactualExplanations obj's underlying member method code with example usage: obj.to_json() and returns: json, json