Working with JSON
What is JSON? First of all, it’s not a language; it’s a data format. While it has JavaScript in the name, it is used by many modern languages to generate, parse, and exchange data. It is also intended to be human-readable; we just have to know how to read it. JSON stores data in a dictionary-like format of key-value pairs. The first term is the key, and the second term is the value. The key is a string, and the value may be another string, a Boolean, a number, an array, or a JSON object. A JSON object consists of one or more key-value pairs, so because the value can be another object, JSON objects can be nested. Let’s type the cmdlet:
PS C:\Users\nickp> (Invoke-WebRequest random.dog/woof.json).content
Then, we get something like the following JSON response.
{"fileSizeBytes":176601,"url":"https://random.dog/6b41dccd-90ca-4ce8-a0e2-800e9ab92aa7.jpg"}
This consists of two key-value pairs:
"fileSizeBytes...