📈 ParseComposerOutdatedJSON
Parses the JSON output of composer outdated --format=json and returns the structured OutdatedResult.
When to use
Use this when you already have the JSON output of composer outdated and need to programmatically list which packages can be upgraded and compare the current version with the latest version. It is the parser called internally by GetOutdatedInfo.
Signature
go
func ParseComposerOutdatedJSON(output string) (*OutdatedResult, error)Parameters
| Parameter | Type | Description |
|---|---|---|
output | string | The raw output of composer outdated --format=json |
Return value
*OutdatedResult: the outdated packages result;Installedis[]OutdatedPackage, andCountis automatically set to the number of installed entries.error: returned when JSON deserialization fails (internally delegates toParseOutdatedResult).
Each OutdatedPackage contains Name, Latest, Installed (current version), LatestStatus (semver-safe-update/update-possible/up-to-date), and Abandoned.
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
output := `{"installed":[{"name":"symfony/console","version":"v5.3.0","latest":"v5.4.0","latest_status":"semver-safe-update"}]}`
result, err := composer.ParseComposerOutdatedJSON(output)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Total %d outdated packages\n", result.Count)
for _, pkg := range result.Installed {
fmt.Printf(" %s: %s -> %s (%s)\n", pkg.Name, pkg.Installed, pkg.Latest, pkg.LatestStatus)
}
}Advanced
- 🔄 This function is equivalent to
ParseOutdatedResult(output)and auto-fills theCountfield. - 🚀 To execute the command and parse in one step, use
GetOutdatedInfo(); with extra options, useGetOutdatedInfoWithOptions(options). Note:composer outdatedmay return a non-zero exit code when there are no outdated packages, but the output is still valid JSON; the wrapper methods handle this case. - 🔗 For security auditing, see
ParseComposerAuditJSON.