Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda