powershell - Nested array and objects are not properly converted to json -
this question has answer here:
description
using
convertto-json in powershell, trying convert following object:  $richmessage = @{     attachments = @(         @{             "mrkdwn_in" = @("text"; "pretext";);             "title" = "title here";             "title_link" = "http://somelinkhere/";             "fallback" = "summary of attachment";             "text" = "message";             "color" = "red";                 })       }  write-host(convertto-json -inputobject $richmessage)   i expected output:
{     "attachments":  [                     {                         "text":  "message",                         "fallback":  "summary of attachment",                         "mrkdwn_in":  ["text" "pretext"],                         "color":  "red",                         "title":  "title here",                         "title_link":  "http://somelinkhere/"                     }                 ] }   but actual output is:
{     "attachments":  [                     {                         "text":  "message",                         "fallback":  "summary of attachment",                         "mrkdwn_in":  "text pretext",                         "color":  "red",                         "title":  "title here",                         "title_link":  "http://somelinkhere/"                     }                 ] }   notes
- i want 
"mrkdwn_in": "text pretext"mrkdwn_in:["text", "pretext"] - if take 
$richmessage = @{ "mrkdwn_in" = @("text"; "pretext"); }produce array expected, when array nested this:$richmessage = @{ attachments = @( @{"mrkdwn_in" = @("text"; "pretext"); } ) }; concatinates strings. - i'm using post rich message slack , allow mark downs in attachments. (see this link)
 
question
how can achieve this?
try adding array value object separately
$richmessage= $richmessage["attachments"][0]["mrkdwn_in"] = @("text", "pretext");   full example:
$richmessage = @{     attachments = @(         @{             "mrkdwn_in" = "";              "title" = "title here";             "title_link" = "http://somelinkhere/";             "fallback" = "summary of attachment";             "text" = "message";             "color" = "red";                 })       }      
Comments
Post a Comment