demo 解读
有了第一篇的基础,操作jolt已经不成问题,对于大部分json的mapping已经得心应手了,本片主要聚焦jolt除了json的mapping功能以外的其他功能。
模式的含义
- modify-default-beta 修改-默认 当左手边不存在或是为空的时候进行转换。
- modify-overwrite-beta 修改-覆盖 保留老数据,如果值相同会更新
数组(Array)相关 - List Functions
json input
{
"scores": [
4,
2,
8,
7,
5
]
}
json spec
[
{
"operation": "modify-overwrite-beta",
"spec": {
// 计算数组长度
"numScores": "=size(@(1,scores))",
// 数组取头取尾
"firstScore": "=firstElement(@(1,scores))",
"lastScore": "=lastElement(@(1,scores))",
// 出不来值
"scoreAtMidPoint": "=elementAt(@(1,scores),2)",
// 数组排序
"sortedScores": "=sort(@(1,scores))" }
}
]
json output
{
"scores" : [ 4, 2, 8, 7, 5 ],
"numScores" : 5,
"firstScore" : 4,
"lastScore" : 5,
"sortedScores" : [ 2, 4, 5, 7, 8 ]
}
数学(Math)相关 - Math Functions
json input