The vanilla approach to get the value of two keys is to use a $['x', 'y']
union.
In your case this could look like this:
$.foo.bar['name1', 'name2']
Unfortunately, not every JSON path engine will return the result in this way (and there are some minor syntax differences as well, i.e some prefer double quotes or no quotes, etc). E.g. when you test your input with the path above online here: https://jsonpath.herokuapp.com/
Using the Jayway tab yields:
{
"name1" : "john",
"name2" : "jane"
}
while the Gatling tab gives the expected result:
[
"john",
"jane"
]
So, give it a try with your JSON path engine at hand. If the result is not as expected post-processing the full or intermediate JSON result in a host programing language might be easier.