Angular valid json format form body

I have an angular application, the form generates \n in the body and its not a valid json, when I submit the form the API complains as its not formatted as valid json:

How I form the form body:

    let body = `{
    "id": "`+ Id+ `",
    "issue_type_id": "`+ issueTypeId + `",
    "space_id": "`+ suitId + `",
    "description": "`+ requestDetails + `",
    "location_details": "",
    "requester_id":"`+ requetUser + `",
    "default_assignment": "true"

and this is the result when I submit the form

     '{\n        "id": "dddddd",\n        "issue_type_id": "ddddddddddddd",\n        "space_id": "ddddddddd",\n        "description": "test ",\n        "location_details": "",\n        "requester_id":"dddddddd",\n        "default_assignment": "true"\n    }'

>Solution :

You have to create a valid JSON object like the following (removing the backtick characters):

let body = {
  "id": Id,
  "issue_type_id": issueTypeId ,
  "space_id": suitId,
  "description": requestDetails,
  "location_details": "",
  "requester_id": requetUser,
  "default_assignment": "true"

Leave a Reply