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.
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?