Format [pscustomobject] instances returned by Invoke-RestMethod or ConvertFrom-Json

Question:

I am trying to create a table from a JSON file I am receiving from a RESTful API.

When I print the property of the json object I get an output like this:

The output I would like to see is this:

In addition, is it possible to avoid displaying a specific key and it’s properties?

Example:

Answer:

You need to add the parent keyname as a property Name to the nested objects:

Note that PowerShell will render the output in list form by default, since your objects have more than 4 properties. Pipe it through Format-List -AutoSize to get tabular output.

Source:

Format [pscustomobject] instances returned by Invoke-RestMethod or ConvertFrom-Json by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply