I want to convert javascript code so that it works in postman

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Here’s an outline with best practices for making your inquiry.

My question:
I want to convert javascript code so that it works in Postman

Details (like screenshots):

How I found the problem:

I’ve already tried:
var responseData = pm.response.json();

// Define a function to limit string lengths within objects
function limitStringLength(obj) {
// Iterate through each object in the array
for (var i = 0; i < obj.length; i++) {
var item = obj[i]; // Get the current object in the array

    // Iterate through each key (property) in the object
    for (var key in item) {
        // Check if the value associated with the key is a string and its length is greater than 4000
        if (typeof item[key] === 'string' && item[key].length > 4000) {
            // If the condition is met, limit the string length to 4000 characters
            item[key] = item[key].substring(0, 4000);
return obj; // Return the modified array of objects


// Apply the limitStringLength function to the “result” array within responseData
responseData.result = limitStringLength(responseData.result);

// Update the response data with the modified “result” array

You can’t update the response through the pm.response function. It’s static.

What you can do, is parse the response into a variable and then update that variable.

You’ve already parsed the response to “responseData”, so you should just be able to loop though that. You don’t really need the function.

Have a look at the following topic which has an example of looping through and updating the response info. You can include your working IF statement into the mix,

Base 64 decoding in API response - :person_raising_hand: Help - Postman Community

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.