Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing specific array item #64

Open
nlaslett opened this issue Jul 12, 2024 · 0 comments
Open

Replacing specific array item #64

nlaslett opened this issue Jul 12, 2024 · 0 comments

Comments

@nlaslett
Copy link

I am having trouble replacing specific array items using the @jdt.path syntax as described on the "Replace" wiki page. The @jdt verbs and attributes don't parse or transform when placed under the array object itself. I was able to get this working by moving the @jdt.replace to the top of the object and then drilling down. Is this a bug?

Sample JSON:

{
  "MyStuff": [
    {
      "Name": "Foo",
      "Value": 123
    },
    {
      "Name": "Bar",
      "Value": 456
    }
  ]
}

The goal is to change the value of the "Foo" item without knowing the ordinal position or how many objects are in the MyStuff array.

Sample transform 1:

{
  "MyStuff": {
    "@jdt.replace": {
      "@jdt.path": "@[?(@.Name == 'Foo')].Value",
      "@jdt.value": 456
    }
  }
}

This should work according to the documentation but all I get is the MyStuff node literally replaced with the transform syntax.

Sample transform 2:

{
  "@jdt.replace": {
    "@jdt.path": "$.MyStuff[?(@.Name == 'Foo')].Value",
    "@jdt.value": 456
  }
}

Alternately, if we place the @jdt.replace at the root and change @jdt.path to start from the root and navigate into MyStuff, it works as expected.

I'm using Visual Studio 2022 + SlowCheetah 4.0.50 in a .NET Framework 4.7.2 project.

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

No branches or pull requests

1 participant