3 ms·
In powershell you would use built ins. To download json over rest you would use Invoke-RestMethod or irm. To convert json to objects you would use ConvertFrom
by vips7L 5y ago
In powershell you would use built ins.
To download json over rest you would use Invoke-RestMethod or irm.
To convert json to objects you would use ConvertFrom-Json.
To select properties from objects you would use Select-Object or select.
Here is a concrete example that I wrote for the rustlings install script: https://github.com/rust-lang/rustlings/blob/main/install.ps1#L73 https://github.com/rust-lang/rustlings/blob/main/install.ps1...
Note that I used Invoke-WebRequest instead of irm here.
- j1elo 5y agoAnd then I guess the shell itself has mechanisms to easily attach or register new commandlets, to allow for easily add custom object processing? I really like the consistency that those commands have: ConvertFrom-<ConverterFormat>. No built in converter for the format you need? I'm just speculating here, but I guess you just need to implement this or that Interface and there you go.
- godtoldmetodoit 5y agoYou can define your own function and use it in your pipeline yes. You can have your function take pipeline input just like the built in cmdlets.
- vips7L 5y agoYes you can write your own cmdlets in either C# or powershell that you can install via modules [0] You can also just write a function in your profile. [0] https://docs.microsoft.com/en-us/powershell/scripting/developer/module/writing-a-windows-powershell-module?view=powershell-7.1 https://docs.microsoft.com/en-us/powershell/scripting/develo...
- d0mine 5y agoIt looks like: `curl <url> | jq .tag_name` Note: curl & jq are independent programs (as long as `curl` produce json text with tag_name in each, the command works, no matter other changes). If ConvertFrom-Json & Select-Object were not builtin, how much information about each other would they need to cooperate? Can an unrelated change in ConvertFrom-Json's output break corresponding Select-Object command? How much are they intertangled?
- bobalob_wtf 5y agoConvertFrom-Json converts json text into a PowerShell object with properties derived from the json. Select-Object (in this instance) selects a property from the object. An unrelated change in ConvertFrom-Json wouldn't change it's basic nature which is to convert json into something you can manipulate with other PowerShell cmdlets.
- vips7L 5y agoCurl to python is actually what happens in the Linux install script [0]. To your point, all cmdlets adhere to an interface so they always return and receive typed data. They don’t really need to know anything except that they’re receiving or giving powershell objects. Non built in commands (native binaries) just pipe a stream of bytes just like any posix shell.