Chapter 7
Activity
Here is my solution:
Figure A.6 – One solution
Line 2 grabs the data in JSON format from the API and puts it in a variable. If we look at the $astronauts
variable, we can see it has two key-value pairs, message
and people
. people
contains an array of JSON objects, which themselves have two key-value pairs; name
and craft
. We can see this in the following figure:
Figure A.7 – Getting the JSON data
So, we know the data we need are in the $astronauts.people.name
key-value pair. All we need to do now is display it in a pleasing manner. We covered how to use ConvertTo-Html
in Chapter 6, PowerShell and Files – Reading, Writing, and Manipulating Data, and this is the way I’ve chosen.
On line 5, we set up a $params
hashtable so we can splat all the parameters we need. I’ve chosen to include a CSS stylesheet that displays a lovely image, but that’s not necessary. This...