The data returned by axios is not equivalent to the parsed JSON response from the request

When making an axios request, I use the following code:

const response = await axios({
  url,
  method,
  headers: headersObject,
  data,
  params: params || {},
});

After making the request, I examine the response:

console.log('response.request.response')
console.log(JSON.parse(response.request.response))
console.log('data')
console.log(response.data)

To my surprise, the response.data is not the same as

JSON.parse(response.request.response)
. In the response.data object, the property labels is undefined, whereas in
JSON.parse(response.request.response)
, the array labels contains the exact labels that I expected. Could there be an issue with converting axios data to an object when a JSON key's value is an array?

Answer №1

It seems like there is some mysterious async behavior happening with console.log(). Although response.data eventually equals JSON.parse(response.request.response), at the moment I'm printing it on the console, they are not the same.

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

Typeahead autocomplete feature in Angular Material

Could you please guide me on how to incorporate autocomplete suggestions in material autocomplete for AngularJS using typeahead? Here's an example format I would like to achieve: Animals: Lion, Tiger Birds: Eagle, Dove Similar to the functionality s ...

Developing an identical design and layout but utilizing a distinct domain name for the company

After being given the task of creating a website identical to an existing one with a different domain name on WordPress, I proposed using the parent HTML source code or cloning it to speed up the project. The client agreed, explaining that starting from sc ...

Prevent the SnackBar from extending to full width in case of a smaller window size

Is there a solution to prevent the SnackBar from spanning the entire width of the screen when the window is narrow? ...

Configuring bitfinex-api-node with Node.js to efficiently handle data from the websocket connection

Apologies for the vague title of this question, as I am not well-versed in programming and even less so in node.js My goal is simple: I aim to utilize the bitfinex-api-node package (a node.js wrapper for the bitfinex cryptocurrency exchange) that I instal ...

Which five key JavaScript concepts should I grasp in order to excel as an AngularJS developer?

Coming from a background of server-side coding, I am delving into the world of AngularJS now. This means I need to have a solid grasp of JavaScript before diving in. If I don't have enough time to master JavaScript completely at the moment, what are ...

Unexpected behavior when using JQuery's .load() method

In my HTML code, I have a main div element with child elements as lists. These lists are dynamically populated with data from the server and each item in the list has a checkbox. When a checkbox is checked, I want that item to move to the bottom of the lis ...

Automating the process of transferring passwords from Chrome Password Manager to a Chrome Extension

Embarking on my first chrome extension journey, I have been developing a password manager app that offers enhanced functionalities beyond the default chrome password manager. A recent request from a client has come in, asking me to gather all passwords fr ...

Response from jQuery AJAX yields an object

Here is the AJAX request I am working with: $(function(){ $("#MPrzezn").typeahead({ hint: true, highlight: true, minLength: 3 }, { name: 'test', displayKey: 'value', ...

PHP retains the POST value even after the page is refreshed

I can't seem to shake off the persistent POST value in my HTML form, even after refreshing the page. The issue seems to be related to a login form that I am working with. To enable communication between PHP and JavaScript, I have implemented cookies ...

What could be causing JQuery to disrupt my HTML code by inserting additional <a> tags?

My dilemma involves this specific chunk of HTML code stored within a javascript string, while utilizing Jquery 1.6.1 from the Google CDN: Upon executing console.log(string): <a><div class='product-autocomplete-result'> & ...

Should I manually unbind the angular.js $destroy event?

Is it automatically unbinding watchers and scope events that are bound with $scope.$on(...) or $scope.$watch(...) when the scope is destroyed in Angular? Let's consider the following code: $scope.$on('someEvents', handleSomeEvent); $scope. ...

A straightforward JaxWS REST service that can handle JSON data

I am currently working on developing a Rest WebService in Java using RestEasy that is able to accept a generic JSonObject with the help of JSON Simple 1.1.1. Here is what I have accomplished so far: @Path("/message") public class TestRestService { @P ...

Initiate timer when mouse leaves; pause timer upon mouse hovering using JavaScript

I am currently working on creating a volume bar for a video. The idea is that when you click the volume button, a div will appear allowing you to control the volume level. As soon as you hover out of the div, a timer will start counting down from 7 and the ...

"Store JSON data into a variable by formatting it through an AJAX POST request

If I want to make a controller call like this: name.php?data={"user":"test","pass":"test"} To retrieve the necessary information using .ajax, I need assistance in configuring the variable to be sent in that specific format. I previously used the follow ...

Dividing JSON array sent from PHP to Android

One of my functions retrieves comments from a database in JSON format, which are then stored in a PHP array and converted to a JSONObject on the mobile device. Here is the relevant snippet of code: JSONObject json2 = CollectComments.collectComments(us ...

I am currently working on creating a shopping cart that includes a delete button for removing items with just a click

I am currently working on developing a shopping cart feature that includes a remove button to delete items when clicked. I have achieved this using the filter method. However, I am facing an issue where after deleting an item and then adding it back, the ...

Dealing with problems related to types in React and TypeScript createContext

Struggling to pass the todos (initial state) and addNewTodo (methods) using React Context hook and typescript. Despite trying multiple solutions, errors persist. Partial generics do not cause issues in the context component, but I encounter the error Cann ...

Sign up for and run a JavaScript function within an ASP.NET Page_Load event

Is there a way to both register and run a JavaScript function in ASP.NET during a Page_Load event? I need the function to validate the content of a textbox, and if it is empty, disable a save button. function Validate(source, arguments) { } ...

Prioritizing reusability and scalability in the design of Vue.js application architecture

I am currently working on adapting an Application that was originally developed for a single country to be used in multiple countries (20+) with only slight modifications needed for each location. I am exploring ways to make the code reusable and scalable ...

Transform the JSON response into a map

I have a functioning code that I am looking to adjust. let table_specs = {'columns': [ {'name': 'Col1', 'width': 7, ....}, {'name': 'Col2', 'width': 8, . ...