Description
Prune selected nodes and their entire descendant subtrees, retaining untouched source order and explicit removed identities.
A parent-record forest represents each node by an exact string ID and a parent ID or null for a root. Depth counts edges toward a root; subtree height counts edges toward the deepest descendant. Node order, identity, cycles and missing references are separate properties that must be checked before structural transformations.
Prune selected nodes and their entire descendant subtrees, retaining untouched source order and explicit removed identities.
When to use this tool
Use this tool to prune selected nodes and their entire descendant subtrees, retaining untouched source order and explicit removed identities.
How to use the tool and how it works
- Enter parentsJson, remove using the definitions below. Serialize JSON text fields in the decoded shape shown below.
- Run the operation. Resolve input-format errors before interpreting an output.
- Read result.parents, result.removed, using the stated boundary, ordering, sign and absence conventions.
Require every requested removal ID to exist. Remove each requested node and all of its descendants, returning retained parent records and removed IDs in original order.1
| Input field | Meaning and units | Accepted input |
|---|---|---|
| parentsJson | JSON array of {id,parent} records. id is an exact string; parent is another exact ID or null for a root. | Text, at most 8,192 UTF-16 code units; narrower grammar/range rules also apply. |
| remove | Existing node IDs whose entire subtrees should be removed. | Dense list of at most 128 literal strings, each at most 8,192 UTF-16 units. |
These decoded structures show the examples inside JSON text fields. Supply their serialized JSON strings as input.
{
"parentsJson": [
{
"id": "a",
"parent": null
},
{
"id": "b",
"parent": "a"
},
{
"id": "c",
"parent": "a"
},
{
"id": "d",
"parent": "b"
}
]
} | Output field | Interpretation |
|---|---|
| result | Object containing the fields below. |
| result.parents | Resulting parent records in retained original order. |
| result.removed | Removed node IDs in original record order. |
{
"input": {
"parentsJson": "[{\"id\": \"a\", \"parent\": null}, {\"id\": \"b\", \"parent\": \"a\"}, {\"id\": \"c\", \"parent\": \"a\"}, {\"id\": \"d\", \"parent\": \"b\"}]",
"remove": [
"b"
]
},
"output": {
"result": {
"parents": [
{
"id": "a",
"parent": null
},
{
"id": "c",
"parent": "a"
}
],
"removed": [
"b",
"d"
]
}
}
} Limitations and assumptions
- This prunes entire subtrees rather than promoting the children of a removed node.
- Structural operations require distinct node IDs, existing non-null parent IDs and no parent cycles; audit tools explicitly state when they accept incomplete structure. Multiple roots are allowed. Matching is exact and case-sensitive.
- Every declared outer field is required and unknown outer fields are rejected. Strings and JSON text have size limits, lists are bounded to 128 entries, and JSON nesting/node counts are bounded. Tighter operation-specific bounds stated above take precedence.
- Ordinary numeric outputs must be finite and within safe-integer magnitude. Exact large lengths/counts use decimal strings. Original record indexes and code-unit positions are zero-based; span ends are exclusive unless stated otherwise.
Alternative or Complementary methods
Use identity and cycle audits to inspect incomplete records, then structural operations on complete forests. Preserve sibling order explicitly when exchanging traversal results with another tree format.
References
Similar or alternative tools
- Parent Forest Ancestor Chain
Explicit complete acyclic parent forests with exact unique string node IDs and null roots; return strict ancestors nearest-first, excluding the query node; unknown IDs reject.
- Parent Forest Child Index
Explicit complete acyclic parent forests with exact unique string node IDs and null roots; index every node’s direct children in source order, retaining leaf nodes with empty lists.