Skip to content

Add Remove-JsonEntry to prune JSON structures #49

Description

Context and request

The data-module verb vocabulary includes Remove-<Noun>Entry for removing elements by criteria, and PSModule/Hashtable ships Remove-HashtableEntry as the reference implementation. Json has no equivalent, so a user stripping secrets, null values, or empty collections before writing a document out has to walk the object graph by hand.

Acceptance criteria.

  • Remove-JsonEntry removes entries from a JSON document by key name and by criteria such as null values and empty collections.
  • Removal applies recursively through nested objects and through objects inside arrays.
  • The input is not mutated; the command returns a new structure.
  • It declares [OutputType()] with matching .OUTPUTS, and carries complete comment-based help with a .LINK to https://psmodule.io/Json/Functions/Remove-JsonEntry/.
  • Behaviour matches Remove-HashtableEntry wherever the operation is analogous.
  • Tests cover key removal, recursive removal, removal inside arrays, null and empty-collection criteria, non-existent keys, and confirmation that the input is unchanged. Coverage stays at or above the 95% target.

Technical decisions

Study Remove-HashtableEntry's parameter names and criteria before designing this. The two commands should agree on what "remove an entry" means, so a user moving between the modules is not surprised.

Non-mutation is a hard requirement. Import-Json returns live objects that a caller may still hold a reference to, and a command that quietly rewrote them in place would be a worse version of the _SourceFile defect this module is already correcting.

Whether this needs SupportsShouldProcess is worth a moment's thought and should be recorded either way. It transforms an in-memory object rather than persisting anything, and the standard reserves ShouldProcess for state changes — so the answer is probably no, but it should be a decision rather than an oversight.

Depth is a parameter from the outset, consistent with the other traversal commands.

Depends on the function-standard work landing first so this is written against the corrected patterns.

Implementation plan

  • Review Remove-HashtableEntry's parameters and criteria
  • Decide and record the criteria set, the recursion rules for arrays, and the ShouldProcess question
  • Write failing tests for key removal, recursive removal, removal inside arrays, null and empty-collection criteria, non-existent keys, and input immutability
  • Implement src/functions/public/Remove-JsonEntry.ps1 with [OutputType()], full comment-based help, and a -Depth parameter
  • Confirm the input object is unchanged after the call
  • Confirm the command appears in Get-Command -Module Json and its reference page generates
  • Confirm coverage still meets the 95% target

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions