ConvertTo de Powershell-json con tabla hash integrada


Estoy teniendo un problema con ConvertTo-Json y estaba tratando de entender el comportamiento y/o lo que estoy haciendo mal.

Considere esta secuencia de comandos:

$val=@{ID=10;Config=@{ID=11;Config=@{ID=12;Config='end'}}}
ConvertTo-json $val
ConvertTo-json @($val)

La primera conversión da esta salida:

{
    "ID":  10,
    "Config":  {
                   "ID":  11,
                   "Config":  {
                                  "ID":  12,
                                  "Config":  "end"
                              }
               }
}

La segunda conversión da esta salida:

[
    {
        "ID":  10,
        "Config":  {
                       "ID":  11,
                       "Config":  "System.Collections.Hashtable"
                   }
    }
]

Parece que en el caso del array la conversión es incorrecta. ¿Alguna idea de por qué está pasando esto?

Author: JPBlanc, 2013-07-29

2 answers

Es un problema con la profundidad, el valor predeterminado es 2, puedes probar:

ConvertTo-json @($val) -Depth 5
 51
Author: JPBlanc,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-31 13:44:45
-Depth $([int32]::MaxValue)

Especifica la profundidad infinita (máximo posible para el cmdlet ConvertTo-Json)

 0
Author: YMM,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-13 09:58:13