Skip to content

Remove Transformation

Davi Paulino edited this page May 4, 2017 · 1 revision
Use: "@jdt.remove" : <Value> (Case sensitive)
Value Type: Behavior
String Removes the node with the given name from the current level
Boolean If true, remove all the nodes from the current level and sets value to null. If false, do nothing
Number, null Not allowed. Generates an error.
Object If the object contains JDT attributes, apply them. See Attributes.
If not, generate error.
Array Applies remove with each element of the array as the transformation value.
If the transformation value is an array, generate an error.

Obs: The @jdt.value attribute cannot be used with this transformation

Example

Source:

{
    "A" : 1,
    "Astar" : 10,
    "B" : 2,
    "C" : {
        "C1" : 31,
        "C2" : 32
    },
    "D" : {
        "D1" : 41,
        "D2" : 42,
        "D3" : 43
    }
}

Transform:

{
    "@jdt.remove" : "Astar",
    "C" : {
        "@jdt.remove" : true
    },
    "D" : {
        "@jdt.remove" : ["D2", "D3"]
    }
}

Result:

{
    // Astar is completely removed
    "A" : 1,
    "B" : 2,
    // All nodes are removed
    "C" : null,
    "D" : {
        "D1" : 41
        // Multiple nodes were removed
    }
}

Path Attribute

The @jdt.path attribute can be used to specify the absolute or relative path to the nodes that should be removed. It can also be used to remove elements from arrays. If the Path attribute is present, the Value attribute is not supported and is ignored if present in the transformation.

Source:

{
    "A" : {
        "RemoveThis" : true
    },
    "B" : {
        "RemoveThis" : false
    },
    "C" : {
        "C1" : 1,
        "C2" : {
            "C21" : 21
        }
    }
}

Transform:

{
    //Remove only matching nodes from this level
    "@jdt.remove" : {
        "@jdt.path" : "$[?(@.RemoveThis == true)]"
    },
    "C" : {
        //Specify a relative path to the node
        "@jdt.remove" : {
            "@jdt.path" : "@.C2.C21"
        }
    }
}

Result:

{
    "B" : {
        "RemoveThis" : false
    },
    "C" : {
        "C1" : 1,
        "C2" : {
        }
    }
}