0

I am working on angular post and try to send a post request with two json object with two diff form bodies in one post request.I have two form but i need to submit the data in one post request.

I and need the post request data in this way.

{
  "detail": {
    "status": "class",
    "service_type": "online",
  },
  "subject": {
    "start_date": "2022-06-28",
    "end_date": "2022-06-29",
    "start_time": "10:00",
    "end_time": "12:30",
  }
}

But After getting the data i am trying to create json object like this. Is this right way to do so?

const body = [{"detail":{"status":"BrakePad","service_type":"online"},"subject":{"start_date": "2022-06-28",} }];

2 Answers 2

0

The payload you send and the one you expect to send are not the same : you send an array, but you ask us to send an object.

Your payload should then be :

const body = {
  detail:{
    status: "BrakePad",
    service_type:"online"
  },
  subject: {
    start_date: "2022-06-28"
  } 
};

// Send with 
this.http.post('YOUR_URL', body).subscribe();

Sign up to request clarification or add additional context in comments.

2 Comments

Can you please tell me how i can push an value to object?
Thanks for the help. I was confused high appreciated for the help. People make it duplicate or mark it delete. But you help my question.
-1

You have an extra , in you object.

It should be [{"detail":{"status":"BrakePad","service_type":"online"},"subject":{"start_date": "2022-06-28"} }].

I'm not sure why you are putting the single object into an array. You can post it as {"detail":{"status":"BrakePad","service_type":"online"},"subject":{"start_date": "2022-06-28"} } if the array is not needed.

You will also want to convert your array to a string before posting it using JSON.stringify. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

2 Comments

There's no "etra comma", JS can handle that without issue, and you don't need to convert to string before sending.
@MGX am i sending in right way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.