code: def add(parent, idx, value):
    
    if isinstance(parent, dict):
      if idx in parent:
        raise JSONPatchError("Item already exists")
      parent[idx] = value
    elif isinstance(parent, list):
      if idx == "" or idx == "~":
        parent.append(value)
      else:
        parent.insert(int(idx), value)
    else:
      raise JSONPathError("Invalid path for operation")
docs: Add a value to a dict.