I have an array of hash table containing key value pairs, like below:
$myTest = @{};
$test1 = @{
Name = "Food1"
Value = "Sandwich"
}
$test2 = @{
Name = "Food2"
Value = "Salad"
}
$myTest["Food1"] = $test1;
$myTest["Food2"] = $test2
On running the command
$myUpdatedTest = $myTest.Values | ConvertTo-Json -Compress
gives the value in
$myUpdatedTest --> [{"Value":"Sandwich","Name":"Food1"},{"Value":"Salad","Name":"Food2"}]
And if I have only $test1 added to the $myTest then the value comes in as {"Value":"Sandwich","Name":"Food1"}
But in the later case I want the value to be inside [] --> [{"Value":"Sandwich","Name":"Food1"}] is there a way to achieve this?
$myUpdatedTest = ConvertTo-Json -InputObject $myTest.Values