"name" : "a",
"type": "container",
"kids": [{
"name": "a1",
"type": "container",
"kids": [{
"name": "a2",
"type": "leaf",
"when": "../a"
}]
}]
}
in when condition i want to validate in node ->parent ->parent is "a" Now how to validate that condition
3
Answers
If your content is XML and you want to check if the parent of the parent of the context is a
a
, you can use this:To process JSON using XPath you need an XPath 3.1 processor.
The tree model for JSON, unlike that for XML, does not have parent pointers, which means you can’t navigate from a node to its parent. This basically means that you have to gather the information you need as you descend the tree, and pass it down in the form of parameters.
Fleshing this out needs a bit more context to understand exactly what you are trying to do.
XPath 3.1 can query JSON as XDM maps/arrays, the lookup operator is
?
so for your sample (a bit formatted)you can test e.g.
and will give true. I am not sure, however, whether you expect the node XPath
/
step syntax to be used, that is not what XPath 3.1 offers; you might find it in some other implementations that internally convert the JSON to some XML.Online XPath 3.1 fiddle.