Kaseya Community

Online JSON file with list of latest software versions - how to parse?

This question is not answered

Hi all, I found a JSON file online that lists the latest versions of various software. I suspect that this would be super useful for many of us.

http://vergrabber.kingu.pl/vergrabber.json

I can't figure out how to pull the version number from the file. Does anyone have a clue?

It's the line containing "version" in each section.

All Replies
  • This was a fun Friday exercise for 30 min. The real issue with this JSON is it is terribly formatted; it uses values as property names. This makes it very annoying to parse and defeats the entire purpose of JSON (or any other standard format like XML).

    Here is a PowerShell (requires v5) script that will parse it and put it in type safe objects:

    Class VersionInfo

    {

       [DateTime]$Ends

       [Bool]$Stable

       [String]$Edition

       [String]$Version

       [Bool]$Latest

       [DateTime]$Released

    }

    Class App

    {

       [String]$Level

       [String]$Name

       [System.Collections.ArrayList]$Versions

    }

    $apps = New-Object -TypeName System.Collections.ArrayList

    $orgJson = (Invoke-WebRequest 'vergrabber.kingu.pl/vergrabber.json').Content | ConvertFrom-Json

    $levels = ($orgJson | Select-Object -Property server,client | Get-Member -MemberType NoteProperty).Name

    foreach ($level in $levels) {

       $levelApps = (($orgJson.$level) | Get-Member -MemberType NoteProperty).Name

       foreach ($app in $levelApps) {

           $a = New-Object -TypeName App

           $a.Level = $level

           $a.Name = $app

           $a.Versions = New-Object -TypeName System.Collections.ArrayList

           $levelAppsVersion = (($orgJson.$level.$app) | Get-Member -MemberType NoteProperty).Name

           foreach ($ver in $levelAppsVersion) {

               $v = New-Object -TypeName VersionInfo

               try {

                   $v.Ends = [DateTime]::ParseExact(($orgJson.$level.$app.$ver.ends), 'yyyy-MM-dd', $null)

               } catch {

                   try {

                       $v.Ends = [DateTime]::ParseExact(($orgJson.$level.$app.$ver.ends), 'MM/dd/yyyy', $null)

                   } catch { }

               }

               try {

                   $v.Released = [DateTime]::ParseExact(($orgJson.$level.$app.$ver.released), 'yyyy-MM-dd', $null)

               } catch {

                   try {

                       $v.Released = [DateTime]::ParseExact(($orgJson.$level.$app.$ver.released), 'MM/dd/yyyy', $null)

                   } catch { }

               }

               $v.Edition = $orgJson.$level.$app.$ver.edition

               $v.Version = $orgJson.$level.$app.$ver.version

               if ($orgJson.$level.$app.$ver.stable -eq 'true') {

                   $v.Stable = $true

               } else {

                   $v.Stable = $false

               }

               if ($orgJson.$level.$app.$ver.latest -eq 'true') {

                   $v.Latest = $true

               } else {

                   $v.Latest = $false

               }

               $a.Versions.Add($v)

           }

           $apps.Add($a)

       }

    }

    $apps | ForEach-Object {$_.Name; $_.Versions | Format-Table}



    Fixed link that was wrong after pasting.
    [edited by: jondle at 1:17 PM (GMT -7) on Apr 20, 2018]
  • OK, I'm impressed!

    I think that the forum has broken the formatting - I get an error:

    At C:\bta\WIP\JSON-Magic.ps1:99 char:58
    + if ($orgJson.$level.$app.$ver.latest -eq 'true') {
    + ~~~~
    The string is missing the terminator: '.
    At C:\bta\WIP\JSON-Magic.ps1:119 char:61
    + $apps | ForEach-Object {$_.Name; $_.Versions | Format-Table}
    + ~
    Missing closing ')' in expression.
    + CategoryInfo : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

  • At a glance, I'd suggest fixing this line

    $orgJson = (Invoke-WebRequest 'vergrabber.kingu.pl/vergrabber.json&).Content | ConvertFrom-Json

    to be this:

    $orgJson = (Invoke-WebRequest 'vergrabber.kingu.pl/vergrabber.json').Content | ConvertFrom-Json

  • OK, that fixed it - thanks :-)

    I just need to figure out how to handle the output now, but there is now decent data.

  • I forgot that the Add() method on the collections had a return value, which gets output to the console. To fix that, add the ' | Out-Null' to the two Add() lines:

    $a.Versions.Add($v) | Out-Null

    $apps.Add($a) | Out-Null

  • Here's another nice list I discovered recently that even includes download URLs - patchmypc.net/.../definitions.xml

  • Uggg...Still very poorly designed data structure (XML in this case). I was going to rewrite my script so I could use XPath to query, but that would have to be fully parsed as well.

  • Agree the data structure is terrible. Why programmers think it's ok to store data in what are ostensibly the 'names' of variables is beyond me. Anyway, if it can be decoded without too much hassle it's still a useful resource as the company producing it is commercially backed and likely to keep it current.

  • It's working - I just wrote a long reply and lost it. Grrr.

    I'll update this later when I have a chance.