Phil-Factor / PSYaml

A Powershell module to convert YAML documents to and from PowerShell objects
MIT License
91 stars 32 forks source link

Single-element arrays are not preserved #13

Open cp880 opened 7 years ago

cp880 commented 7 years ago

convertfrom-yaml does not preserve single-element arrays.

Example:

# Create a hash with two key-value pairs.  Both values are arrays, but one of them 
# has just a single element
$j = [ordered]@{
  apac = @('Australia')
  emea = @('Italy', 'Finland')
}

#Confirm that both values are arrays
PS C:\> $j.apac.gettype().name
Object[]
PS C:\> $j.emea.gettype().name
Object[]

# Convert to yaml.  Good so far, we still have two arrays/sequences.
PS C:\> $j | convertto-yaml
---

  apac:
  - 'Australia'
  emea:
  - 'Italy'
  - 'Finland'

# Convert back to a PowerShell object and we lose one of the arrays.
# Now we have one array and one scalar.  We should have two arrays.
PS C:\> $j = $j | convertto-yaml | convertfrom-yaml
PS C:\> $j.apac.gettype().name
String
PS C:\> $j.emea.gettype().name
Object[]