Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

     '{\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"
};
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading