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?

3
  • 1
    stackoverflow.com/questions/49136148/… Commented May 6, 2021 at 3: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 Commented May 6, 2021 at 3: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 Commented May 6, 2021 at 3:46

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.