Removing parameters outputted in JSON response. How to remove array and only show specific array of fields?

Hello - looking for help here. I’m learning so I really appreciate any help the community can provide.

When I make a GET request, the data is returned in JSON format. I specify certain QSP’s, just standard filters and sorting. In the response, there is an array of data for the “sort” and “filters” and also other meta data about the call.

I’m looking for help to remove the “sort”, “filters”, and “additional_info” from the response body. Is there a pre-script request that can be used or another method? As you can see in the screenshot, I still want the “transactions” array of data to be displayed, just not the other meta data about the GET request.


1-28-2020 10-47-25 AM

Hi @Akochiss! Welcome to the community. :slight_smile:

There isn’t a way to remove these properties from the actual response, but you can manipulate the response data in a Test script and then do whatever you need to do with it. Example test script:

// declare a variable, and assign it the response body as a value
let responseData = pm.response.json() 

// delete unwanted properties
delete responseData.sort; 
delete responseData.filters;
delete responseData.additional_info;

// Store your modified response data as a string in the environment for later use

Then, say you have another request where you need to POST this data. If it’s stored exactly as it needs to be sent, you can just include it anywhere in your request by adding {{data}}.

…or if you need to reference this in another script, use:

// retrieve stringified object from the environment
let dataString = pm.environment.get('data');
// parse the string back into a JSON object
let dataJson = JSON.parse(dataString);
// then do something with with...

Hope that helps! Let me know if you have any questions.

Thank you @john-paul
Still hitting a snag that I hope you can help with!

When i add the script to the “Tests” in postman, and then declare the {{data}} in the body, the response doesn’t seem impacted.

Here is where the {{data}} is stored in the body:

And the response still showing the “transactions”, which is expected/desired - but not the “Sort”, “Filters” and “additional_info”.

Any idea on what I may be missing?

Thank you so much

Here is the response - even with the script and {{data}} in the body.

Adding that the content header type is urlencoded

Hi @Akochiss.

The script I shared won’t affect the actual response — what it does is extract data from your response, and whittle it down to just what you need. This subset of the original response data can then be inserted wherever else you need it (like in a subsequent request).

Can you tell me a bit more about what you’re trying to accomplish over all?

Thanks @john-paul.

I’m trying to dump the JSON response into an integration platform (Dell Boomi) where I can then map the fields to a system of record (via a SOAP API POST into batch).

Since the response has the meta data associated with the GET request (the “sort”, “filtering”, and “additional_data”, the integration platform cannot distinguish between valid “transaction” data which should be integrated to the system of record and the additional GET request data which isn’t a transaction but just details about the response.

So the ultimate goal is to only return the result “transactions” array - and not include any other data.

Thanks again

Ah, got it. Thanks for the details.

In that case, you’ll just want to store the array contents instead of omitting everything else.

So, based on the response you posted, this would look like:

var responseJson = pm.response.json();
var transactions = responseJson.result.transactions;
var transactionsStringified = JSON.stringify(transactions);
// check to see if format matches what the API expects


This code should work if transactionsStringified matches what your API expects. I’ve included a console.log() so you can check the Postman console (command + option + C on Mac) for the exact structure.

Thanks @john-paul… really helpful.

I’ve dropped the script into Postman, but all the console logs look exactly the same. In the console, the response doesn’t include the query params and other GET call related data - but can you confirm what I should expect with this type of script.

Thanks very much for your patience.

Hi @Akochiss I want to make sure I correctly understand how your requests are setup.

I’m assuming you have:

  1. One GET request that gets the transactions data
  2. One POST request that sends the transactions data — this is where the {{data}} variable should be included

Is that right?

Thanks @john-paul.

I see the gap. Can you please walk though the POST request piece a bit more. This is where I’m mixed up with how to execute the POST. I create the variable but I see now that I am creating the POST request.


Ah, got it.

So, the first GET request should have the script that grabs the response data and sets an environment variable.

The POST request should contain the {{data}} variable, wherever it is needed. My guess is that this would be in the request body (assuming you want to submit the whole transaction array), but I would check the documentation for your API to determine this.

1 Like

Thanks very much for all your help @john-paul — you’re a pro!

1 Like

No problem! Glad I could help. :slight_smile: Let me know if you need anything else!