Author Posts

August 11, 2013 at 4:09 am

I have a working knowledge of PowerShell arrays, however, when I was experimenting with ConvertTo-JSON, I came across a construction that I did not fully understand.

$Name = @"

What is the significance of the @"..."@ construction?
Is there an online reference to this type of array?

Here is my full example:

$Input = @"
"Contacts": [
{ "FirstName":"John" , "LastName":"Evans" , "Email":"" },
{ "FirstName":"Mira" , "LastName":"Cody" , "Email":"" },
{ "FirstName":"Trevor" , "LastName":"Williams", "Email":"" }
$Victim = $Input | ConvertFrom-Json
$Victim.Contacts | Format-Table FirstName, LastName, Email -AutoSize

August 11, 2013 at 7:06 am

In PowerShell, @"..."@ (and it's picky about where on the line those appear) are a here-string – basically, a big block string. What you're seeing inside the string is Javascript Object Notation (JSON). Javascript "understands" that format and converts it to an array. It's similar to how .NET serializes and deserializes using XML; Javascript uses JSON. It isn't an array per se; it's a textual representation (serialization) of objects and their properties.

August 12, 2013 at 12:49 am

Thanks for your explanation – useful. With the help of this article I am now up to speed with the 'here-string' concept.