Postman is displaying [object object] as the return value, but the actual value is not

Currently, I am working on automating tasks using Postman

One interesting aspect is the presence of a vehicles array in the body

{
   "Vehicles":[
      {
         "car":"{{car}}",
         "bike":"{{bike}}"
      }
   ]
}

My task requires me to modify it as shown below

{
   "Vehicles":"[{{vehicles}}]"
}

To achieve this modification, I have created a pre-request script

let car, bike;
var vehicles = {
    car: data.vehicles.car,
    bike: data.vehicles.bike
}
pm.variables.set("vehicles", vehicles);

The data for the vehicles is sourced from an external file and looks like this

[
   {
      "Vehicles":[
         {
            "car":"BMW",
            "bike":"YAMAHA"
         }
      ]
   }
]

I executed it through the collection runner and noticed that the request body showed vehicles:[object object], indicating that the data was not being successfully passed

Answer №1

This code snippet demonstrates the process of converting objects into strings. When objects are converted into strings, the output may be shown as [object, object]. If you are utilizing a JSON file as an external source, you can utilize the JSON.stringify() method to resolve this issue. Update the section below in your existing code:

let carStringified, bikeStringified;
var vehicles = {
    car: JSON.stringify(data.vehicles.car),
    bike: JSON.stringify(data.vehicles.bike)
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error occurs when attempting to clear the cache storage

useEffect(async () => { caches.open('my-cache') }, [token, user_id]) Upon trying to log out of the application, const logoutFunc = () => { localStorage.clear() caches.keys().then((list) => list.map((key) => { ...

Best Practices for Managing Asynchronous Updates in Angular Controllers

Let me explain my current setup -- I have a controller that utilizes a service to perform some tasks and then fetches data asynchronously. Right now, the data is returned after a timeout, but ideally it would involve more complex operations: This is how m ...

The Discord.js .cleanContent attribute does not show up when using Object.keys() and cannot be logged

My Discord.js Message object should contain a property called .cleanContent, according to the documentation, and it should be a string. console.log(message.cleanContent) works correctly, but console.log(message) does not display the cleanContent propert ...

Display content exclusively in PDF format

On my HTML page, I have two sections - one for inputting values and the other for viewing a PDF. To ensure that the PDF view is hidden until explicitly requested, I need it to remain invisible by default. It should only appear as a PDF when someone clicks ...

The POST function in jQuery often returns the [Object object] result

Looking to extract a string from a PHP file using jQuery's post method. function getString(string) { return $.ajax({ type: 'POST', url: 'scripts/getstring.php', data: { 'string': string } ...

Angular5 causing all divs to have click events at once instead of individually triggered

I am a beginner when it comes to working with Angular and I have encountered an issue. I created a click event on a FAQ page in Angular 5, but the problem is that when I click on one FAQ, they all open up instead of just the targeted one. Here is my TypeS ...

Leveraging MVC 4 for Web Service Development

I am currently in the process of developing a web service using MVC 4 and HTML for the client interface. One issue I am facing is that my HTML file is located outside of the application, while my MVC service is running on Visual Studio IIS Express. I' ...

Create a custom Android home screen widget using JavaScript or another programming language

I have a project in mind to create an Android App and include a home-screen widget. While I know it can be done with Native Android, my preference is to use JavaScript for development. Would anyone happen to know of any other solutions that allow the use ...

error encountered when working with date arrays in JavaScript

I find myself perplexed by this particular issue. Although the following code snippet appears to function correctly, it exhibits some peculiar behavior. var tmpcurdte = eval(dataSource[i].startDate); tmpcurdte.setDate(tmpcurdte.getDate() + 1); while (tm ...

Displaying a div on click using Jquery will only impact one div at a time

I am encountering an issue with my WordPress setup. Within my loop, I have a clickable link that toggles a div to show or hide content. However, since each item in the loop uses the same class, clicking on one link activates all of them simultaneously. &l ...

How can I stop a browser from refreshing when I click the mouse?

After taking steps to prevent the browser back button from functioning by clearing history and disabling key events for page refresh, I am now seeking a way to also stop mouse clicks on the browser's refresh button. Can anyone offer assistance with th ...

Unable to transform JSON Object into a List

Here are the classes I have: public class Datum { public bool Prop1 { get; set; } public bool Prop2 { get; set; } public bool Prop3 { get; set; } public bool Prop4 { get; set; } public bool Prop5 { get; set; } public bool Prop6 { g ...

JavaScript treats string as a primitive value

When it comes to JavaScript, a String is considered a primitive value. However, it can also be treated as a String object. In programming terms, a primitive value refers to a value assigned directly to a variable. This raises the question: var d = "foo"; ...

Trigger the React useEffect only when the inputed string matches the previous one

Currently, I am in the process of creating my own custom useFetch hook. export const useFetch = <T extends unknown>( url: string, options?: RequestInit ) => { const [loading, setLoading] = useState(false); const [error, setError] = ...

Responsive Tabs with Material-UI

Can MUI's Tabs be made responsive? This is what I currently have: https://i.stack.imgur.com/KF8eO.png And this is what I aim to accomplish: https://i.stack.imgur.com/b3QLc.png ...

Utilize ViewChild to handle changing elements in Angular 2 and Ionic 2 applications

I am facing an issue where I want to dynamically add multiple IonicSlides, but I am unable to use @viewChild. Can anyone suggest a solution for this problem? Template.html : <div *ngFor="let name of title;let i = index;"> <ion-slide ...

Error 400 encountered when trying to access National Weather Service data

Encountering a 400 error when making a simple NWS GET request for a point JSON dataset. The issue seems to be with the jQuery process, which is adding extra text after the longitude value in the URL - https://api.weather.gov/points/39.5,-105.5?_=16303483 ...

Enzyme's simulate() failing to produce expected results with onChange event

I am facing an issue with a component and its related tests: import React from 'react'; import PropTypes from 'prop-types'; function SubList (props) { var subways = ['', '1', '2', '3', & ...

Tips for identifying if the function "res.end()" has been executed or not

Is there a method to determine if the res.end function has been triggered? var http = require('http'); http.createServer(function (req, res) { some_function_may_called_end(req, res); // Is there a way to check for this? if(res.is_ended = ...

executing jQuery toggle on freshly generated content

I have a webpage that I designed using jQuery. Within this page, there is a table with rows assigned specific color classnames (e.g., tr class="yellowclass"). Users can filter the rows by clicking checkboxes to show/hide tables of different colors. The i ...