json Nifi -使用震动规范拆分列

r1zhe5dt  于 2023-03-24  发布在  其他
关注(0)|答案(1)|浏览(135)

我需要转换我的JSON值

[
  {
    "fornecedor_frete": "EMPRESA BRAS. CORREIOS E TELEGRAFOS - OR SAO PAULO",
    "nfe_composicao": "40814-1"
  },
  {
    "fornecedor_frete": "EMPRESA BRAS. CORREIOS E TELEGRAFOS - OR SAO PAULO",
    "nfe_composicao": "40817-1"
  }
]

收件人:

{
  "documentos": [
    {
      "numeroDocumento": "40814",
      "serie": "1"
    },
    {
      "numeroDocumento": "40817",
      "serie": "1"
    }
  ]
}

可以使用jolt spec?(在'-'之前拆分,在'-'之后拆分)
谢谢

hi3rlvi2

hi3rlvi21#

您可以通过使用左手的"*-*"表达式,在shift转换规范中用破折号分割这些值,例如

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "nfe_*": {
          "*-*": { // split values by dash
            "#numeroDocumento": "documentos[&3].&(1,1)", // &(1,1) : going 1 level up the tree to grab the 1st asterisk
            "#serie": "documentos[&3].&(1,2)"            // &(1,2) : going 1 level up the tree to grab the 2nd asterisk
          }
        }
      }
    }
  },
  {// exchange key-value pairs
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "$": "&3[&2].@0"
          }
        }
      }
    }
  }
]

http://jolt-demo.appspot.com/站点上的***演示***是

另一种方法使用modify-overwrite转换规范到**split**,例如

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "*": "=split('-',@(1,&))"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@nfe_composicao[0]": "documentos[&1].numeroDocumento",
        "@nfe_composicao[1]": "documentos[&1].serie"
      }
    }
  }
]

网站http://jolt-demo.appspot.com/上的***演示***是

相关问题