I have following JSON object which is dynamically created and can contain special characters in the names e.g. O'Brian in Last Name and special characters in Notes.
$jsonData = @"
{
"ReqId": 37,
"First Name": "John",
"Middle Name": "",
"Last Name": "O'Brian",
"Preferred Name": "John",
"Date": "04/28/2021 05:00:00",
"Email": "[email protected]",
"Notes": "This is a note with Special characters"
}
"@ | ConvertTo-Json;
I want to use this JSON data and convert it to HTML table format. Then pass this HTML data as a value of the key in another JSON object which will then be sent to API.
$convData = ConvertTo-Html -InputObject ($jsonData);
$apiJson = @"
{
"Title" : "This is Test",
"Description" : "This is Test Description.<br ><br /> $convData"
}
"@
$apiJson needs to be valid JSON so that API can parse it as a JSON object successfully.
I tried ConvertTo-HTML method but it is not working and gives empty table. Also I want just <table>...</table> part and need to remove other tags.
{
"Test" : "This is Test",
"description" : "This is Test.<br > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//E
N" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/x
html"> <head> <title>HTML TABLE</title> </head><body> <table> <colgroup><col/></colgroup> <tr>
<th>*</th></tr> <tr><td>539</td></tr> </table> </body></html>"
}
Need help. Thank you.