Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

223
Vistas
How to pass an array of object into a payload in a JSON format while making a api request

I have an array of objects like this.

var arr = [
{name: 'myName', age: 25, city: 'myCity'},
{name: 'myName1', age: 25, city: 'myCity1'}
];

Now, I need to pass this arr array into a payload as a JSON object. I used JSON.stringify(arr) and then passed the data. But it is getting converted into a form-data and the payload format is like below;

[{name: 'myName', age: 25, city: 'myCity'},{name: 'myName1', age: 25, city: 'myCity1'}]:

If you have noticed a colon at the end of the payload, seems like it converted my array as a property name to the form data. Can you help me to pass the array as a JSON object.

Code that is used to call the API method is,

{
 type: 'POST',
 method: 'POST',
 dataType: 'json',
 url: 'url of the api call',
 beforeSend: function(header, settingsData){
    Object.keys(settingsData.options).forEach(headerKey){
       headerKey.setHeader(headerKey, settingsData.options[headerKey]);
    }
    return settingsData;
 },
 disableDefaultError: true
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

My comment was half correct.

  • Keep dataType: 'json'
  • add contentType: 'application/json' since the default is 'application/x-www-form-urlencoded; charset=UTF-8'
{
 type: 'POST',
 method: 'POST',
 dataType: 'json',
 contentType: 'application/json', // <- this is needed
 url: 'url of the api call',
 beforeSend: function(header, settingsData){
    Object.keys(settingsData.options).forEach(headerKey){
       headerKey.setHeader(headerKey, settingsData.options[headerKey]);
    }
    return settingsData;
 },
 disableDefaultError: true
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda