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
pm.response.json(responseData);