I am writing a PowerShell script which passes a JSON to a C# module.
The following is the JSON:
{
"Header": {
"Message": {
"EDept": [
"Computers",
"Electronics",
"Electricals"
],
"EId": "001",
"Emp": "All"
},
"AnotherArray": [
"E1",
"E2",
"E3"
],
"ID": "JOPP"
}
}
I basically have two Arrays/List which are : "EDept" & "AnotherArray". AnotherArray is fine but EDept is not taken as an array !!
This is PSScript:
$Header = @{}
$Header.Add("ID", "JOPP")
$message = @{}
$message.Add("Emp", "All")
$message.Add("EId", "001")
$EDept = @("Computers", "Electronics", "Electricals")
$message.Add("EDept", $EDept)
$Header.Add("Message", $message)
$anotherArray = @("E1", "E2", "E3")
$Header.Add("AnotherArray", $anotherArray)
$main= @{}
$main.Add("Header", $Header)
$mainjson = $main | ConvertTo-Json
Write-Output ($mainjson)
but the output that I get is:
{
"Header": {
"Message": {
"EDept": "Computers Electronics Electricals",
"EId": "001",
"Emp": "All"
},
"AnotherArray": [
"E1",
"E2",
"E3"
],
"ID": "JOPP"
}
}
If you see here my AnotherArray
is fine but "EDept" is taken a single string rather than a array. I am defing both in the same way.
What am I doing wrong?