Comment 1 for bug 1790115

Revision history for this message
Sylvan Le Deunff (sylvanld) wrote :

I was also looking for something similar and couldn't find anything about it in the documentation.

It seems that the canonical way to do it is to combine "let" and "context pass" (->) operators to first define a variable that stores the value you need to use before context is overriden.

```
EXPRESSION='let(target_age => $.target_age)->$.users.where($.age=$target_age)'

cat > context.json <<EOF
{
    "users": [
        {"name": "toto", "age": 18},
        {"name": "tata", "age": 19},
        {"name": "titi", "age": 18}
    ],
    "target_age": 18
}
EOF

yaql -d context.json -n "$EXPRESSION"
```