def deduplicate(input_json, input_path): input_path_arr = input_path.strip().split(".") if len(input_path_arr) > 1: json_path = ".".join(input_path_arr[0: len(input_path_arr)-1]) input_objs = JSONUtil.extract_objects_from_path(input_json, json_path) else: input_objs = JSONUtil.to_list(input_json) # print "Got objects:", json.dumps(input_objs) last_path_elem = input_path_arr[len(input_path_arr)-1] for input_obj in input_objs: if last_path_elem in input_obj: last_input_obj = input_obj[last_path_elem] if isinstance(last_input_obj, list): seen_objs = set() rest = list() for part in last_input_obj: part_str = json.dumps(part) if part_str in seen_objs: # last_input_obj.remove(part) continue else: seen_objs.add(json.dumps(part)) rest.append(part) #print rest input_obj[last_path_elem] = rest return input_json