I need to create a singleton
complex array. Background: I am trying to automate Let's Encrypt DNS challenge with GoDaddy. But the question is just about PS objects.
Suppose I have the following JSON object, which is my target notation
[
{
"data": "string",
"port": 0,
"priority": 0,
"protocol": "string",
"service": "string",
"ttl": 0,
"weight": 0
}
]
I try to initialize the variable via Powershell as follows
$goDaddyDnsBody=@(
@{
"data"= $dnsChallenge;
"port"= 1;
"priority"= 0;
"ttl"= 600;
"weight"= 0
}
)
The above code is supposed to create an array containing only one item
But when I try to Write-Host ($goDaddyDnsBody |ConvertTo-Json)
I get only the first element, not the whole array
{
"weight": 0,
"priority": 0,
"data": ".................",
"ttl": 600,
"port": 1
}
The question is obvious: how can I make sure, without necessarily using string manipulation, that the object created is an array?