Are there any efficient ways to handle the task of importing raw JSON data and posting it to a server using an import function?
For example, if a user copies and pastes the following JSON:
{
"name": "testing",
"design": [
{
"name": "test",
"comments": [
{
"short": "123",
"long": "1234567890"
}
],
"maxMark": 0
}
]
}
I would like all of that information to be sent to the server. However, I am unsure about the best approach to achieve this.
Currently, I have a basic form set up:
<modal #importModal [keyboard]="false" [backdrop]="'static'">
<modal-header [show-close]="false">
<h4 class="modal-title">Importing a module</h4>
</modal-header>
<modal-body>
<form name="importForm" [ngFormModel]="importForm" (ngSubmit)="importForm.valid" novalidate>
<textarea class="form-control" rows="20" #data='ngForm' [ngFormControl]="importForm.controls['data']"></textarea>
</form>
<pre>{{importForm.value | json }}</pre>
</modal-body>
<modal-footer>
<button type="button" class="btn btn-danger" (click)="importModal.dismiss()"><i class="fa fa-close"></i> Close</button>
<button type="button" class="btn btn-primary" type="submit" [disabled]="!importForm.valid" (click)="importModal.dismiss() && submitImport(importForm.value)"><i class="fa fa-floppy-o"></i> Submit</button>
</modal-footer>
</modal>
However, the value displayed for the form is currently:
"data": "{\n \"name\": \"testing\",\n \"design\": [\n {\n \"name\": \"test\",\n \"comments\": [\n {\n \"short\": \"123\",\n \"long\": \"1234567890\"\n }\n ],\n \"maxMark\": 0\n }\n ]\n}"
Do I need to stringify and then strip the data? What is the best way to convert this back into JSON format?