Description
Using
ConvertTo-Json in Powershell, I am trying to convert the following object:
$richmessage = @{
attachments = @(
@{
"mrkdwn_in" = @("text"; "pretext";);
"title" = "title here";
"title_link" = "http://somelinkhere/";
"fallback" = "Summary of the attachment";
"text" = "message";
"color" = "red";
})
}
write-host(ConvertTo-Json -InputObject $richmessage)
I expected to get this output:
{
"attachments": [
{
"text": "message",
"fallback": "Summary of the attachment",
"mrkdwn_in": ["text" "pretext"],
"color": "red",
"title": "title here",
"title_link": "http://somelinkhere/"
}
]
}
But the actual output is:
{
"attachments": [
{
"text": "message",
"fallback": "Summary of the attachment",
"mrkdwn_in": "text pretext",
"color": "red",
"title": "title here",
"title_link": "http://somelinkhere/"
}
]
}
Notes
- I want the
"mrkdwn_in": "text pretext"to bemrkdwn_in:["text", "pretext"] - If we take
$richmessage = @{ "mrkdwn_in" = @("text"; "pretext"); }this will produce the array as expected, but when the array is nested like this:$richmessage = @{ attachments = @( @{"mrkdwn_in" = @("text"; "pretext"); } ) }; it concatinates the strings. - I'm using this to post a rich message to Slack and allow mark downs in the attachments. (see this link)
Question
How can I achieve this?