Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!