How to enable this textbox for JsonPath Expression input (in POSTMAN Tool) under “Visualize” tab?
I want to use JSONpath queries to filter data of Response Body in POSTMAN Tool.
How to enable this textbox for JsonPath Expression input (in POSTMAN Tool) under “Visualize” tab?
Hey @hcmehta9279
Welcome to the community!
You would need to import the template
into your app - You can use the Run in Postman
button to do this.
It contains some example requests that can be used to see it working but the code in the Tests
tab should work when placed with another request.
(1) jsonpath package is required to install for postman to enable JSONpath queries to filter data of Response Body in POSTMAN Tool ?
(2) which template i need to import in postman to enable JSONpath queries to filter data of Response Body in POSTMAN Tool ?
Please reply on urgent basis.
Please view snapshot.
The template is in the link I provided, that’s all that’s needed to use the functionality in the image.
Have you imported the Collection from the link into the app. It will become clearer once you do that
hey, sorry if I post in the bad reply. I’m looking for solution for my projet. I include json file in castlemock and since postman with a request i would like find a string.
Example
Castle mock Body:
{
"elements": [
{
"activityKey": {
"phase": "X",
"activityType": "VOI",
"registrationNumber": "Mxxxyyy",
"startTime": "2024-02-07T21:30:00"
},
.....
},
On postman with a request i would like find “registrationNumber”
Welcome to the Postman Community!
Is that an example of the request body or the response body?
Are you using the template I created to use JSONPath? I have to be honest, It was created a long time ago and i’m not actually sure if it works anymore in the latest versions.
it’s the response body. And since postman, i’d like find just one part of the body (here : registrationNumber) with a request. How i can use JSONPath?
The original thread is based on a visualizer template that I created, are you using that code as a base to use JSONPath with Postman?
I’m not really following what you have done so far, you’re going to need to elaborate more of your answers or use some screenshots to help provide more information.
You don’t as Postman doesn’t natively support JSONPath.
You can use a Post-response script to parse the JSON response to a JavaScript object and then target the elements that way.
The registration number is held within the activityKey object, which is held within the elements array.
const response = pm.response.json() // parse response to JavaScript object
// target the element using standard JavaScript dot notation.
let regNo = response.elements[0].activityKey.registrationNumber
// console log the element to ensure its been targetted correctly
console.log(regNo);
// a simple test
pm.test("Registration number is correct", () => {
pm.expect(regNo).to.eql("Mxxxyyy");
});
You can however use JSONPath with the visualizer to some extent but that is a more advanced topic which you still wouldn’t do based on your example response. You would parse and then use the JavaScript object in the visualizer instead.
Sorry, i explain with capture beacause i’m not developer but test: i include json on castlemock (see picture
Then since postman i’d like have result of my search with a request
![image|690x117](upload://AsEHI0gQKhk8h1
I’m a tester, but I’m still not understanding the scenario you are trying to test so can you please try to elaborate.
I’d rather not guess.
You have a request, that I assume is working and returning data.
What exactly do you want to do with the response?
Do you want to run some tests against the response, or do you just want to visualize the response? (or both).
by indicating the registerNumber in my request, postman must return the response to me with all the information attached to the registerNumber. From this the developer must query to extract all the data to calibrate his application
I’m still not following.
Postman will return a response based on what you’ve sent and what the API is design to return.
As I’ve mentioned, Postman does not support JSONPath natively in the sandbox, apart from in the visualizer and even then that is by downloading JavaScript libraries, and requires a fair knowledge of JavaScript to maintain.
Your JSONPath command is just searching for a single registration number.
The equivalent when working with JavaScript objects is to use the find or filter functions.
The inputs you have in that last screenshot are completely different to the body you provided in your original post.
If you provide an example “response” body with at least two objects\records, I will show you how to filter or find a registration number.
Please use the pre-formatted text option in the editor and cut and paste (no images).
{"items":
[
{"registrationNumber":"M123456","population":"XXX","rank":"YYY","trigram":"LGF","firstName":"PRENOM1","lastName":"NOM1","aircraftQualification":"EJ","base":"CDG","email":"[email protected]"}
,{"registrationNumber":"M234523","population":"XXX","rank":"YYY","trigram":"KGR","firstName":"PRENOM2","lastName":"NOM2","aircraftQualification":"CJEJ","base":"CDG","email":"[email protected]"}
,{"registrationNumber":"M999888","population":"XXX","rank":"YYY","trigram":"EME","firstName":"PRENOM3","lastName":"NOM3","aircraftQualification":"EJ","base":"CDG","email":"[email protected]"}
,{"registrationNumber":"M112233","population":"XXX","rank":"YYY","trigram":"CPN","firstName":"PRENOM4","lastName":"NOM4","aircraftQualification":"EJ","base":"CDG","email":"[email protected]"}
,{"registrationNumber":"M960550","population":"PNC","rank":"CDC","trigram":"HAM","firstName":"PRENOM5","lastName":"NOM5","aircraftQualification":"EJ","base":"CDG","email":"[email protected]"}
,{"registrationNumber":"M960574","population":"PNC","rank":"CDC","trigram":"LAU","firstName":"PRENOM6","lastName":"NOM6","aircraftQualification":"EJ","base":"CDG","email":"[email protected]"}
,{"registrationNumber":"M960494","population":"PNC","rank":"CDC","trigram":"CLA","firstName":"PRENOM7","lastName":"NOM7","aircraftQualification":"CJEJ","base":"CDG","email":"[email protected]"}
,{"registrationNumber":"M960460","population":"PNC","rank":"CDC","trigram":"BEN","firstName":"PRENOM8","lastName":"NOM8","aircraftQualification":"CJEJ","base":"CDG","email":"[email protected]"}
An example using find().
const response = pm.response.json();
let search = response.items.find(obj => obj.registrationNumber === "M123456");
console.log(search);
Which returns the following in the console log.
OK thanks, but about castlemock it necessary to define a special configuration (path or jsonpath, …)