2015-09-25 10 views
8

PowerShell non riesco a corretta di andata e ritorno questo oggetto JSON:Come di andata e ritorno questo JSON per PSObject e schienale in PowerShell

{ 
    "settings": { 
     "minimumApproverCount": 2, 
     "creatorVoteCounts": false, 
     "scope": [ 
      { 
       "refName": "refs/heads/d14rel", 
       "matchKind": "Exact", 
       "repositoryId": "a290117c-5a8a-40f7-bc2c-f14dbe3acf6d" 
      } 
     ] 
    } 
} 

Supponendo $json è una stringa, questo comando:

$json | ConvertFrom-Json | ConvertTo-Json 

produce il male JSON fuori di esso:

{ 
    "settings": { 
        "minimumApproverCount": 2, 
        "creatorVoteCounts": false, 
        "scope": [ 
            "@{refName=refs/heads/d14rel; matchKind=Exact; repositoryId=a290117c-5a8a-40f7-bc2c-f14db 
e3acf6d}" 
           ] 
       } 
} 

Avviso si ottiene il "campo di applicazione" sbagliato variabile. C'è un modo per risolvere questo problema?

risposta

9

Utilizzare il parametro Depth con valore 3 o superiore. Il valore predefinito 2 non è sufficiente, i dati più profondi vengono semplicemente convertiti in stringhe.

$json | ConvertFrom-Json | ConvertTo-Json -Depth 3 

uscita

{ 
    "settings": { 
        "minimumApproverCount": 2, 
        "creatorVoteCounts": false, 
        "scope": [ 
            { 
             "refName": "refs/heads/d14rel", 
             "matchKind": "Exact", 
             "repositoryId": "a290117c-5a8a-40f7-bc2c-f14dbe3acf6d" 
            } 
           ] 
       } 
} 
Problemi correlati