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

"@jdt.Path" is not a valid attribute for this transformation. #48

Closed
ameer-thasthahir opened this issue Apr 27, 2023 · 0 comments
Closed

Comments

@ameer-thasthahir
Copy link

ameer-thasthahir commented Apr 27, 2023

When I was trying to use the JDT by following the https://github.com/Microsoft/json-document-transforms/wiki.

Everytime when i use the @jdt.path in the transformation file, i continuously get the below Exception message

"@jdt.Path" is not a valid attribute for this transformation.

Below is the C# code, I have used by referring the wiki https://github.com/microsoft/json-document-transforms/wiki/Rename-Transformation

`
var engine = new JsonTransformation($"./{specName}");

var json = engine.Apply($"./{inputName}");

json.Position = 0;
using (StreamReader reader = new StreamReader(json, Encoding.UTF8))
{
    var anotherVaue =  reader.ReadToEnd();

    Console.WriteLine(anotherVaue);
}`

Source file is
{ "A" : { "RenameThis" : true }, "B" : { "RenameThis" : false }, "C" : [ { "Name" : "C01", "Value" : 1 }, { "Name" : "C02", "Value" : 2 } ] }

Transform file

{ "@jdt.rename" : { "@jdt.Path " : "$[?(@.Rename == true)]", "@jdt.Value" : "Astar" }, "C" : { "@jdt.rename" : { "@jdt.path" : "@[*].Name", "@jdt.value" : "Nstar" } } }

When i try to do it i continuously received the below error.

"@jdt.Path" is not a valid attribute for this transformation.

After all the Trial and error by assuming something wrong with the source or transformation file. I downloaded the source code to find out the reason.

It seems, In JdtRename file. https://github.com/microsoft/json-document-transforms/blob/a9bf106829b3c9d8b73fdf67d37891f95d3f6ee8/src/Microsoft.VisualStudio.Jdt/Processors/Attributes/JdtAttributeValidator.cs Line Number 67. It tries to validate the property name and AttributeNames are equal.
Currently in our case, The property name would be @jdt.path and AttributeNames contains the EnumValues of [Path,Value].

Since it always fail and return the "@jdt.Path" is not a valid attribute for this transformation.

When i try modifying it in a below way. it started working fine.

MicrosoftTeams-image (1)

I changed. from

internal static JdtAttributes GetByName(this IEnumerable<JdtAttributes> collection, string name) { // The default value for the enum is 0, which is None return collection.SingleOrDefault(a => a.FullName().Equals(name)); }

To This

internal static JdtAttributes GetByName(this IEnumerable<JdtAttributes> collection, string name) { // The default value for the enum is 0, which is None return collection.SingleOrDefault(a => a.FullName().ToLower().Contains(name.ToLower())); }

Is it a bug?

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