![]() ![]() ![]() Let’s start by looking at an array of objects. The syntax for arrays and hashtables is a bit different in JSON. Arrays, on the other hand, do not care about duplicated data, but are somewhat limited when trying to add or search for items in the array (compared to a hashtable). But it’s really easy to lookup data based on a key and return the value. With a hashtable, each key must be a unique object you can’t re-use the same key name within a single hashtable. $body = 'value1'Įach type of collection has various pros and cons. Here’s an example, and note that the curly brace is used to build hashtables. As the name implies, this is a collection of keys that describe an object. ![]() $body = also known as key-value pairs, are a bit different. Below, I’ve created an array by storing three strings into the $body variable. Put simply, an array is a collection of objects. I’ve found that most articles covering JSON assume you already have a perfect grasp of the syntax, rather than going into what’s going on with the code. This post will cover some of the basics of reading JSON, including how to format the strings so that they make sense in PowerShell, so that you can build your own scripts. This is cleaner looking, easier to manipulate while writing the code, and avoids any double-conversion losses when toggling back-and-forth between PowerShell objects and a JSON string. I prefer to build using PowerShell objects, convert to JSON, and then ship the results off to a URI, rather than editing native JSON directly in PowerShell. The challenge is converting the syntax for arrays and key-value pairs ( hashtables) from native JSON to native PowerShell. This seemed like a nifty way to condense a few different pieces of information into a rich formatted Slack message with a bit of PowerShell code. While tinkering around with Slack’s Incoming Webhooks feature, I came upon the ability to add message attachments. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |