0

The json payload look like this:

{
  "clients": [
    {
      "scope": "scope1",
      "claim": "scope1",
      "id": ["123", "567"]
    },
    {
      "scope": "scope2",
      "claim": "claim2",
      "id": ["321", "765"]
    }
  ]
}

When try to get the json in pwsh variable, I'm not getting the id values and it just displays System.Object[].

> $inputjson = (((get-content .\inputfile.json) -Join " " ) | convertfrom-json )

> echo $inputjson

 clients                                                                               
 -------                                                                 
 {@{scope=scope1; claim=scope1; id=System.Object[]}, @{scope=scope2; claim=claim2; id=System.Object[]}}

Any help on how to get these array with array values?

Zeigeist
  • 3,755
  • 3
  • 20
  • 22
  • 1
    https://stackoverflow.com/questions/49136148/how-to-parse-json-response-in-powershell – Chetan May 06 '21 at 03:24
  • 2
    you still can access the values, try `$json.clients` without `echo`. and `$json.clients[0].id` for example will return the ids for the scope1 – Santiago Squarzon May 06 '21 at 03:33
  • @SantiagoSquarzon : Thanks. I can access it, but the actual problem is the API is not accepting the payload because of this System.Object[] in "id" field. I'm using ```Invoke-RestMethod -Method POST -Headers $headers -Body $inputjson -Uri $uri``` to call the API – Zeigeist May 06 '21 at 03:46

1 Answers1

0

As @SantiagoSquaron said in the comment, we could access the array content by $inputjson.clients[0].id. Thanks @SantiagoSquaron.

Zeigeist
  • 3,755
  • 3
  • 20
  • 22