microsoft / microsoft/json-document-transforms

Easier way to replace an array?

Open
#60 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PowerShell
Stars
115
Forks
39
PR merge metrics
No merged PRs in 30d

Description

Under the "Default Transformation" section there is an array listed as "SupportedVersions" that says the default transformation for arrays is append but when going to the "Replace" section, it does not show how to replace an array.

Let's assume I have 2 appsettings.json files that need merged so that the SupportedVersions array is replaced when listed under the Settings section.

First file

{
    "Settings": {
        "SupportedVersions" : [1, 2]
    }
}

Second file

{
    "Settings": {
        "SupportedVersions" : [3, 4]
    }
}

Expected output

{
    "Settings": {
        "SupportedVersions" : [3, 4]
    }
}

I can get this to work by using the following but is there an easier way that I can't find in the documentation?
This works but is long

{
    "Settings": {
        "@jdt.replace" : {
            "@jdt.path" : "$.SupportedVersions",
            "@jdt.value" : [3, 4]
        }
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Default Transformation and Replace Transformation sections in the linked wiki pages, then verify the documented array behavior against the two appsettings.json examples in the issue. Document the shorter supported syntax if one exists; otherwise clarify the existing @jdt.replace form and its expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.