I've seen a lot of questions about JSON and PowerShell these past hours and none helped me find a solution to this particular problem. And I'm sure it's something easy.
I want to extract all the url fields of the plugins objects in this JSON object (original URL is this: https://updates.jenkins.io/update-center.json):
{
"connectionCheckUrl": "http://www.google.com/",
"core": {
...
},
"deprecations": {
...
},
"generationTimestamp": "2021-05-19T12:16:52Z",
"id": "default",
"plugins": {
"42crunch-security-audit": {
"buildDate": "Oct 06, 2020",
"defaultBranch": "master",
"dependencies": [
...
],
"developers": [
...
],
"excerpt": "Performs API contract security audit to get a detailed analysis of the possible vulnerabilities and other issues in the API contract.",
"gav": "io.jenkins.plugins:42crunch-security-audit:3.8",
"issueTrackers": [
...
],
"labels": [
...
],
...
"title": "42Crunch REST API Static Security Testing",
"url": "http://archives.jenkins-ci.org/plugins/42crunch-security-audit/3.8/42crunch-security-audit.hpi",
},
"AnchorChain": {
...
"url": "http://archives.jenkins-ci.org/plugins/AnchorChain/1.0/AnchorChain.hpi",
...
},
... many hundreds more ...
}
...
}
The plugins object contains one object per plugin, where the plugin's name is the object's key. So I somehow have to iterate over all plugin objects and look for the url property.
I want/have to do this using PowerShell (v5.1) but cannot find an easy way. Here is where I am stuck:
$all = (Get-Content(".\update-center.json") | convertfrom-json)
$all.gettype().fullname
$plugins = $all.plugins
$plugins.gettype().fullname
I get this result:
System.Management.Automation.PSCustomObject
System.Management.Automation.PSCustomObject
And now I hope to iterate over the individual plugin objects and simply get the url key's property, but I'm stuck:
$plugins | get-member -MemberType NoteProperty | foreach name | foreach $plugins.$_.url
The get-member is supposed to get the individual plugins I suppose, but hours of poring over PowerShell documentation have clearly fried my brain. Help! :-)