Accessing the property
(key) instead of the value is a feature not present in the original JSONPath specifications, and only a few implementation support this feature. So, no luck using the JMeter JsonPath Plugin/Extractor extracting only property names.
For instance, JsonPath-Plus for JavaScript offers the operator ~
for grabbing property names of matching items.
As an alternative, you could use JSR223 Groovy to get the results from JSON:
import groovy.json.JsonSlurper;
import groovy.json.JsonOutput; //if output as JSON is needed
JsonSlurper JSON = new JsonSlurper ();
jsonResponse = JSON.parseText(prev.getResponseDataAsString());
//println json.keySet() //[-1, 222, 223, 224, recordsCount]
vars.put("firstName", response.members[2].firstName.toString());
Set<String> keySet=obj.keySet();
List<String> keys = [];
// iterate over the key set, adding only numbers to result list
for(String key:keySet){
if(key.isNumber())
keys.add(key);
}
//println(keys); //[-1, 222, 223, 224]
def output = JsonOutput.toJson(keys); //convert to JSON string if neede
//println(output); //["-1","222","223","224"]
vars.put("jsonKeys", output.toString());
Demo: Online Groovy sample.
More information: