How do I send a JSON array using axios?
The method for sending a JSON array using axios is as follows:
import axios from 'axios';
const data = [
{ name: 'John', age: 25 },
{ name: 'Jane', age: 30 },
{ name: 'Bob', age: 35 }
];
axios.post('/api/endpoint', data)
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
The data here is a JSON array, sent to a specified API endpoint using the axios.post method. On the server side, you can use a corresponding framework/library (such as Express) to parse and handle the received JSON array data.