Understanding a particular PowerShell Array

This topic contains 2 replies, has 2 voices, and was last updated by  Guy Thomas 4 years, 10 months ago.

  • Author
  • #9294

    Guy Thomas

    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":"john.evans@cp.com" },
    { "FirstName":"Mira" , "LastName":"Cody" , "Email":"mira.cody@cp.com" },
    { "FirstName":"Trevor" , "LastName":"Williams", "Email":"trevor.williams@cp.com" }
    $Victim = $Input | ConvertFrom-Json
    $Victim.Contacts | Format-Table FirstName, LastName, Email -AutoSize

  • #9295

    Don Jones

    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.

  • #9323

    Guy Thomas

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


You must be logged in to reply to this topic.