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

158
Vistas
Typescript JSON.stringify, remove key property name

The following JSON Stringify is not working. I just realized my API Request should look like this without a Key, for api to execute correctly.

{[{"resource":"Providers"},{"resource":"ServiceLocation"}]}. // this is the json request

instead of this with key bootStrapInputList.

{"bootStrapInputList":[{"resource":"Providers"},{"resource":"ServiceLocation"}]}

How do I create a proper header, without a key?

Data Types:

export type BootStrapInput = {
  resource: string;
  query?: any;
};

export type BootStrapResponse = {
  status: number;
  resource: string;
  body: any;
};

Service:

export const getBootstrap = (
  bootStrapInputList: Array<BootStrapInput>,
): any => {
  return kfetch(`/api/BootStrap`, {
    method: 'put',
    body: JSON.stringify({ bootStrapInputList }),
  });
};

// this json stringify creates {"bootStrapInputList":[{"resource":"Providers"},{"resource":"ServiceLocation"}]}

Service Execute:

(async () => {
  let bootStrapList: Array<BootStrapInput> = [
    { resource: 'Providers' },
    { resource: 'ServiceLocation' },
  ];
  const datatest = await getBootstrap(bootStrapList); // this is not working correctly
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

I think what you actually want is to do the following on service:

body: JSON.stringify({ ...bootStrapInputList }),

That line should result in:

{[{"resource":"Providers"},{"resource":"ServiceLocation"}]}

I saw jsN00b comment and while you said it worked and of course, I believe you and I'm happy you solved it, but doing:

body: JSON.stringify( bootStrapInputList ),

would result in:

[{"resource":"Providers"},{"resource":"ServiceLocation"}]

Which is not the same (no object wrapping the array).

Good luck!

about 4 years ago · Santiago Gelvez 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