Skip to content

Make Json round-trip data without loss or pollution #32

Description

Context and request

Two defects make Json unsafe for its most obvious use case — reading a JSON file, changing a value, and writing it back. Both were reproduced locally against main.

Export-Json -Depth is silently inconsistent: it defaults to 2 and is only honoured on the -Compact path, because the pretty path delegates to Format-Json, which hard-codes -Depth 100. The same command therefore truncates nested objects to strings like "@{l4=deep}" with -Compact and preserves them without it.

Import-Json adds a _SourceFile note property to every object it returns. Any import, modify, export round-trip writes that property into the output file. examples/General.ps1 Example 18 demonstrates exactly this sequence and would produce a polluted file.

Scope

In scope: depth handling across Format-Json and Export-Json, and the provenance property added by Import-Json.

Out of scope: the pipeline-overwrite semantics of Export-Json, which are documented and intentional, and any change to Format-Json's indentation engine.

Aggregate acceptance criteria

  • A JSON file imported and re-exported without modification produces structurally equivalent content.
  • Export-Json -Depth <n> produces the same nesting depth with and without -Compact.
  • Nothing that Import-Json returns carries a property that was not present in the source document.
  • Regression tests cover both behaviours and fail against the current implementation.

Technical decisions

Both are corrections rather than redesigns, and each is independently correctable in one pull request, so they are Bug children rather than a single oversized fix.

Neither correction preserves the current behaviour behind a switch. The depth inconsistency has no plausible caller depending on it, and _SourceFile is undocumented in the command's help — it appears only in the examples file. Whether provenance should be reintroduced as an opt-in is a design question for a follow-up, not part of the correction.

Both changes are user-visible in output content and warrant Minor rather than Patch.

Implementation plan

Delivery is tracked through the native sub-issues on this PBI.

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