Given one object ("includeFields") specifying which properties from another object ("toBeFiltered") should be extracted into a new resulting object:
{
"toBeFiltered": {
"a": "AAA",
"b": "BBB", // Excluded from the result as "includeFields" doesn't include "b"
"c": "CCC"
},
"includeFields": {
"a": true,
"c": true
}
}
When: Some JsonPath expression checking which field names in "toBeFiltered" are also present in "includeFields"
Then:
{
"a": "AAA",
"c": "CCC"
}
Is it possible to do the with JsonPath and if so - what would the JsonPath (Jayway) expression look like?
JSON Path isn't going to perform transformations like this. It's only a query syntax: it'll only tell you if and where items are.
There are other syntaxes which can do that, like JMESPath, which is largely based on JSON Path.