Something like this would do the same, if somebody implemented a tool called jsed:
jsed '
Object.fromEntries(
$("Directory").map(
x => [
x.name + " has children",
x.children && x.children.length != 0
]
)
)'
Interestingly enough there is already a tool called jsed which seems to kind of do this...
https://www.npmjs.com/package/jsedEdit: Note the jQuery part of it is for advanced cases like searching for specific nodes in the tree, then navigating back up to the parent. Basically the cases like "<Work>[-1][children]" from the jtc guide, I would write as: '$("Work").parent().find("children")'