-
Notifications
You must be signed in to change notification settings - Fork 36
Replace Transformation
Davi Paulino edited this page May 4, 2017
·
1 revision
Use: |
"@jdt.replace" : <Value> (Case sensitive) |
---|
Value Type: | Behavior |
---|---|
Primitive | Replaces the current node with the given value |
Object | If the object contains JDT attributes, apply them. See Attributes. If not, replaces the node with the given object. |
Array | Applies merge with each element of the array as the transformation value. If the transformation value is an array, replace the node with the given array. |
Source:
{
"A" : {
"A1" : "11"
},
"B" : {
"1B" : 12,
"2B" : 22
},
"C" : {
"C1" : 31,
"C2" : 32
}
}
Transform:
{
"A": {
"@jdt.replace": 1
},
"B": {
"@jdt.replace": {
"B1": 11,
"B2": 12
}
},
"C": {
// Double brackets are needed to specify
// the array as the transformation value
"@jdt.replace": [[
{
"Value": 31
},
{
"Value": 32
}
]]
}
}
Result:
{
"A" : 1,
"B" : {
"B1" : 11,
"B2" : 12
},
"C" : [
{
"Value": 31
},
{
"Value": 32
}
]
}
The @jdt.path
attribute can be used to specify the absolute or relative path to the nodes that should be replaced. It can also be used to specify objects within arrays that should be replaced.
Source:
{
"A" : {
"A1" : 11,
"A2" : "Replace"
},
"B" : [
{
"ReplaceThis" :true
},
{
"ReplaceThis" : false
}
]
}
Transform:
{
"@jdt.replace" : {
"@jdt.path" : "$.A.A2",
"@jdt.value" : 12
},
"B" : {
"@jdt.replace" : {
"@jdt.path" : "@[?(@.ReplaceThis == true)]",
"@jdt.value" : {
"Replaced" : true
}
}
}
}
Result:
{
"A" : {
"A1" : 11,
"A2" : 12
},
"B" : [
{
// The entire object was replaced
"Replaced" : true
},
{
"ReplaceThis" : false
}
]
}