Hi guys,
Could someone explain me the following JSONAta absurdity ?
Thanks heaps
Because it's Tuesday
you need to use % (Parent)
This will select the 'parent' of the current context value. Here, we define 'parent' to be the enclosing object which has the property representing the context value.
%
(Parent)
This is the only operation which searches 'backwards' in the input data structure. It is implemented by static analysis of the expression at compile time and can only be used within expressions that navigate through that target parent value in the first place. If, for any reason, the parent location cannot be determined, then a static error (S0217) is thrown.
Replace items[item]
with items[%.item]
since items
and item
are both at the same level in the hierarchy, and using items
starts you down one leg of the hierarchy, to get item
you need to go back up so you can access item
Alternatively, for older Node-RED/JSONata versions: items[$$.item]
, where $$
is always referencing to the root object passing in.The Parent operator is by far the preferred solution, and I'm glad it got added; I think it was Steve who came up with the %
syntax. For older versions though, that's not available, and paging to the object from root level or lower level is often best there; it helps to set variables as you go down the tree, so you have higher level parts of the tree available through that variable. But again, %.item
is preferred in the newer version, this is for backwards compatible answers.
Thanks heaps guys, btw who is Steve ?
That would be @shrickus
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.