官网介绍
Defaultr is a kind of JOLT transform that applies default values in a non-destructive way.
For comparison :
Shitr walks the input data and asks its spec "Where should this go?"
Defaultr walks the spec and asks "Does this exist in the data? If not, add it."
个人解读
JOLT一个类型default,简单概括,通过Jolt Specification给input json补充默认值,补充的思路是,判断是否存在,不存在则加一个默认值。
通配符
| 通配符 | 含义 |
| | | or或者的意思,用于匹配键值 |
| * | 将此默认值应用于此级别的所有输入键 |
| [] | 向Defaultr发出信号,指示此密钥的数据应为数组 |
例一
input json
{"Rating": 3,"SecondaryRatings": {"quality": {"Range": 7,"Value": 3,"Id": "quality"},"sharpness": {"Value": 4,"Id": "sharpness"}}}
Jolt Specification
{"RatingRange" : 5,"SecondaryRatings": {"quality|value" : {"ValueLabel": "a","Label": null,"MaxLabel": "Great","MinLabel": "Terrible","DisplayType": "NORMAL"},"*": {"Range" : 5,"ValueLabel": null,"Label": null,"MaxLabel": "High","MinLabel": "Low","DisplayType": "NORMAL"}}}
SecondaryRatings下的value或者quality下的不存在以下字段走默认值
"ValueLabel": "a","Label": null,"MaxLabel": "Great","MinLabel": "Terrible","DisplayType": "NORMAL"
*表示SecondaryRatings除了value和quality下的对象,默认补充下面的默认值
"Range" : 5,"ValueLabel": null,"Label": null,"MaxLabel": "High","MinLabel": "Low","DisplayType": "NORMAL"
output json
{"Rating": 3,"SecondaryRatings": {"quality": {"Range": 7,"Value": 3,"Id": "quality","MaxLabel": "Great","MinLabel": "Terrible","Label": null,"ValueLabel": "a","DisplayType": "NORMAL"},"sharpness": {"Value": 4,"Id": "sharpness","MaxLabel": "High","Label": null,"DisplayType": "NORMAL","MinLabel": "Low","Range": 5,"ValueLabel": null}},"RatingRange": 5}

例二
input json
{"photos": [{"name": "a.png","url": "http://www.bazaarvoice.com"}, {"name": "b.png","url": "http://www.bazaarvoice.com"}, {"name": "c.png","url": "http://www.bazaarvoice.com"}]}
Jolt Specification
{"photos[]": {"0": {"url": "http://www.bazaarvoice.com","caption": ""}}}
output json
{"photos": [{"name": "a.png","url": "http://www.bazaarvoice.com","caption": ""}, {"name": "b.png","url": "http://www.bazaarvoice.com"}, {"name": "c.png","url": "http://www.bazaarvoice.com"}]}

文章转载自NIFI实战,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




