Skip to content

Replacing specific array item #64

@nlaslett

Description

@nlaslett

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions