Skip to content

Single-element arrays are not preserved #13

Description

@cp880

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[]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions