Skip to content

Rename Transformation

Davi Paulino edited this page May 4, 2017 · 1 revision
Use: "@jdt.rename" : <Value> (Case sensitive)
Value Type: Behavior
Primitive Not allowed. Generates an error
Object If the object contains JDT attributes, apply them.
See Attributes. If not, it must only contain key-value pairs where the key is the name of the node that should be renamed and the value is a string with the new name.
Array Applies rename with each element of the array as the transformation value.
If the transformation value is an array, generate an error.

Obs: Renaming the root node is not allowed and will generate an error.

Example

Source:

{
    "A" : {
        "A1" : 11,
        "A2" : {
            "A21" : 121,
            "A22" : 122
        }
    },
    "B" : [
        21,
        22
    ],
    "C" : 3
}

Transform:

{
    "@jdt.rename" : {
        "A" : "Astar",
        "B" : "Bstar"
    }
}

Result:

{
    // Does not alter result
    "Astar" : {
        "A1" : 11,
        "A2" : {
            "A21" : 121,
            "A22" : 122
        }
    },
    // Does not depend  on object type
    "Bstar" : [
        21,
        22
    ],
    // Does not alter siblings
    "C" : 3
}

Path Attribute

The @jdt.path attribute can be used to specify a node to rename. Absolute or relative paths can be specified to the node. Renaming elements of arrays is not supported and should generate an error.

Source:

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

Transform:

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

Result:

{
    // Only this node matches the path
    "Astar" : {
        "RenameThis" : true
    },
    "B" : {
        "RenameThis" : false
    },
    // Renaming nodes from an object 
    // in the array is allowed
    "C" : [
        {
            "Nstar" : "C01",
            "Value" : 1
        },
        {
            "Nstar" : "C02",
            "Value" : 2
        }
    ]
}