fix: normalize nil slices to empty arrays in JSON output
Description
fix: normalize nil slices to empty arrays in JSON output
This fixes issue #8093 (closed) where JSON output from commands like
glab token list would return null instead of [] for empty lists.
The fix adds a PrintJSON() helper in a new print_json.go file within
the iostreams package. This helper uses reflection to normalize nil
slices to empty slices before JSON marshaling, ensuring consistent API
responses where empty collections are always represented as []
instead of null.
Changes:
- Add print_json.go with PrintJSON() method and reflection-based nil slice normalization
- Add print_json_test.go with comprehensive tests for PrintJSON()
- Update token list and ci get commands to use PrintJSON()
- Update test golden file expectations to match new behavior
The solution respects Go semantics where nil slices are valid and only normalizes them at the JSON output boundary, keeping the fix isolated to the presentation layer.
Closes #8093 (closed)
Related Issues
Resolves #[issue_number]
How has this been tested?
Screenshots (if appropriate):
Edited by Kai Armstrong