从流文件进行颠簸转换

时间:2018-07-06 11:43:05

标签: apache-nifi jolt

我有一个流文件,其内容文件如下

{
"name" :"aaa",
"address": "address line1",
"pincode": "pincode",
"mobile": "mobile",
"State" " "state"
}

我想输出以下内容

 {
  "details": "primary details",
  "home":[
  {
    "name": "name",
    "address": "address",
    "mobile": "mobile",
    }
 ],
  "state": "state"
}

有人可以帮我吗?

1 个答案:

答案 0 :(得分:3)

这个震动规格怎么样?

获取名称,地址,密码,手机,状态键的所有值,并为详细信息添加默认键/值,但不能确定如何将默认详细信息键/值保持在第一位

    [{
    "operation": "shift",
    "spec": {
        "name": "home[0].name",
        "address": "home[0].address",
        "mobile": "home[0].mobile",
        "State": "state"
    }
}, {
    "operation": "default",
    "spec": {
        "details": "prirmay details"
    }
}]

输出:

{
    "home": [{
        "name": "aaa",
        "address": "address line1",
        "mobile": "mobile"
    }],
    "state": "state",
    "details": "prirmay details"
}

如果您想保留名称,地址键的一些默认值,请使用以下缓冲说明:

[{
    "operation": "shift",
    "spec": {
        "mobile": "home[0].mobile",
        "State": "state"
    }
}, {
    "operation": "default",
    "spec": {
        "details": "primary details",
        "home[]": {
            "*": {
        "name": "name",
        "address":"address"
            }
        }
    }
}]

输出:

 {
    "home": [{
        "mobile": "mobile",
        "name": "name",
        "address": "address"
    }],
    "state": "state",
    "details": "primary details"
}