com.bazaarvoice.jolt
public class Removr extends Object implements SpecDriven, Transform
{
"~emVersion" : "2",
"id":"123124",
"productId":"31231231",
"submissionId":"34343",
"this" : "stays",
"configured" : {
"a" : "b",
"c" : "d"
}
}
With the desired output being :
{
"id":"123124",
"this" : "stays",
"configured" : {
"a" : "b"
}
}
This is what the Removr Spec would look like
{
"~emVersion" : "",
"productId":"",
"submissionId":"",
"configured" : {
"c" : ""
}
}
* Removr Wildcards
'*' Wildcard
Valid only on the LHS ( input JSON keys ) side of a Removr Spec
The '*' wildcard can be used by itself or to match part of a key.
'*' wildcard by itself :
To remove "all" keys under an input, use the * by itself on the LHS.
// example input
{
"ratings":{
"Set1":{
"a":"a",
"b":"b"
},
"Set2":{
"c":"c",
"b":"b"
}
},
}
//desired output
{
"ratings":{
"Set1":{
"a":"a"
},
"Set2":{
"c":"c"
}
},
}
//Spec would be
{
"ratings":{
"*":{
"b":""
},
},
}
In this example, "Set1" and "Set2" under rating both have the same structure, and thus we can use the '*'
to allow use to write more compact rules to remove "b" from all children under ratings. This is especially useful when we don't know
how many children will be under ratings, but we would like to nuke certain part of it across.
'*' wildcard as part of a key :
This is useful for working with input JSON with keys that are "prefixed".
Ex : if you had an input document like
{
"ratings_legacy":{
"Set1":{
"a":"a",
"b":"b"
},
"Set2":{
"a":"a",
"b":"b"
}
}
"ratings_new":{
"Set1":{
"a":"a",
"b":"b"
},
"Set2":{
"a":"a",
"b":"b"
}
}
}
A 'rating_*' would match both keys. As in Shiftr wildcard matching, * wildcard is as non greedy as possible, which enable us to give more than one * in key.
For an ouput that removed Set1 from all ratings_* key, the spec would be,
{
"ratings_*":{
"Set1":""
}
The Spec file format for Removr is a tree Map@Inject public Removr(Object spec)
Copyright © 2014. All Rights Reserved.