Skip to content

fix!: do not unwrap single-item arrays in --json output#9160

Open
yetanotheraryan wants to merge 2 commits intonpm:latestfrom
yetanotheraryan:json-unwrap-fix
Open

fix!: do not unwrap single-item arrays in --json output#9160
yetanotheraryan wants to merge 2 commits intonpm:latestfrom
yetanotheraryan:json-unwrap-fix

Conversation

@yetanotheraryan
Copy link
Copy Markdown

@yetanotheraryan yetanotheraryan commented Mar 29, 2026

BREAKING CHANGE: npm view --json now always returns an array when a semver range is used as the version specifier, even if the range matches exactly one version.

Fixes npm view --json returning a single object/value when a semver range matches exactly one version.

References

Fixes npm/statusboard#1074
Related to npm/statusboard#1068

@yetanotheraryan
Copy link
Copy Markdown
Author

@wraithgar @owlstronaut I’ve opened a PR to address this : npm/statusboard#1068

The change ensures that --json output consistently returns arrays, even for single-item results.

Happy to make any adjustments if needed!

verified the same on local -
when only one version is returned and still the output is in array format.
existing working as ususal.

Copy link
Copy Markdown
Contributor

@owlstronaut owlstronaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a breaking change, we'll need a fix!: and a footer of BREAKING CHANGE describing the break for npm 12.

Thanks for looking in to this!

Comment thread lib/commands/view.js Outdated
Comment on lines 245 to 248
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the fix this can be removed. Maybe keep the 2nd line only?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@owlstronaut I have kept the 2nd line and removed other comments, and pushed in the PR

I have also added fix!: in the PR along with BREAKING CHANGE in description of the PR.
Let me know if anything else is required.

@yetanotheraryan yetanotheraryan changed the title fix: do not unwrap single-item arrays in --json output fix!: do not unwrap single-item arrays in --json output Apr 18, 2026
@yetanotheraryan
Copy link
Copy Markdown
Author

@owlstronaut I have pushed the requested changes in the PR, please let me know if anything else is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dont unwrap any single item arrays in view --json

2 participants