def correct_json_format_for_db()

in microservices/extraction_service/src/utils/change_json_format.py [0:0]


def correct_json_format_for_db(output_dict, input_json):
  """Function to add a list of dictionary for key value mapping
       to input list of dictionary json
  Input:
    output_dict: list of dictionary with key value mapping
    input_json: list of dictionary json
  Output:
    input_json: list of dictionary json"""
  # traverse input json
  for item in input_json:
    # traverse the keys in dictionary
    for entity in output_dict[0].keys():
      # if keys are matched
      if item.get("entity") == entity:
        # reassign input json value to new one
        item["value"] = output_dict[0][entity]
  return input_json