Understanding a particular PowerShell Array

Welcome Forums General PowerShell Q&A Understanding a particular PowerShell Array

This topic contains 2 replies, has 2 voices, and was last updated by

5 years, 5 months ago.

  • Author
  • #9294

    Points: 0
    Rank: Member

    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

    Points: 1,785
    Helping HandTeam Member
    Rank: Community Hero

    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

    Points: 0
    Rank: Member

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


The topic ‘Understanding a particular PowerShell Array’ is closed to new replies.