To demonstrate, let's take a JSON string as an example. So I decided to build a ConvertTo-Hashtable function that takes an object returned from ConvertFrom-Json and converts it to a hash table. This command does some processing under the hood as well, like performing some escaping I sometimes don't want. But I've found when you've got JSON data that contains deeply nested arrays, for example, you'll begin to see some problems. PowerShell has a native command called ConvertFrom-Json, but it doesn't convert data to a hash table. Instead, it's much better to convert that JSON string to a native hash table. ![]() But what if I'm going to use this data in other parts of my script? It's possible to carry around a JSON string all day in a script, but it's going to be tough to parse that out and get to the data you need. ![]() But what then? Lots of APIs return JSON, which is great. Combine Arrays and Hash Tables in PowerShell for Fun and Profit In the fourth post, I answered a question that was sent to about that the. ![]() PowerShell can easily query these REST APIs using the Invoke-RestMethod command or Invoke-Webrequest.
0 Comments
Leave a Reply. |