Reputation: 1
i have an array variable which has some integer value. I need to feed that variable in some other function as comma separated value, can someone point me how it can be done. Please note am using powershell to perform the required things.
thanks, Pankaj
Upvotes: 0
Views: 2566
Reputation: 25001
You can use the -join
operator to join array elements. This creates a single string that is comma-delimited.
$array -join ','
Since you are trying to create a JSON array, it is easier to work with PowerShell custom objects first and then convert them to JSON.
$obj = [pscustomobject]@{'Name'='export-docs';'fileIds'=$array}
$botBody = $obj | ConvertTo-Json -Depth 10
$botBody # JSON string
Upvotes: 2