简体   繁体   English

从 Apache NiFi 中的数组中提取值

[英]Extract the value from an array in Apache NiFi

I have a JSON with this structure:我有一个 JSON 这种结构:

{
  "documentos": [
    {
      "valorNota": 229.2,
      "tipoDocumento": "PRE_NOTA_FISCAL",
      "cnpjEmissorNota": "02130525000177",
      "cnpjRemetente": "02130525000177",
      "cnpjUnidade": "02130525000177",
      "cnpjDestinatario": "14586674000124",
      "valorFreteRealizadoNota": 0,
      "serie": "1",
      "valorFreteCalculadoNota": 1000,
      "tipoOperacao": "SAIDA",
      "dataEmissao": "2022-12-05 11:03:00",
      "numeroNota": 744659
    }
  ],
  "dataEmissaoConhecimento": "2022-12-05 11:03:00.0",
  "localizacaoDestinoConhecimento": 3002171,
  "localizacaoOrigemConhecimento": 3001956,
  "cepOrigemConhecimento": 44079006,
  "cepDestinoConhecimento": 48880000,
  "valorFreteRealizadoConhecimento": 0,
  "oidConhecimento": 10802880097,
  "valorFreteCalculadoConhecimento": 1000
}

I need to extract the value of "numeroNota" (can be with EvaluateJsonPath or other processor).我需要提取"numeroNota"的值(可以使用EvaluateJsonPath或其他处理器)。

How can I do this?我怎样才能做到这一点?

Thanks谢谢

One option is to use a shift transformation spec within a JoltTransformJSON processor such as一种选择是在JoltTransformJSON处理器中使用移位转换规范,例如

[
  {
    "operation": "shift",
    "spec": {
      "docu*": { //the level of "documentos" array
        "*": { //the indexes of the array
          "numeroN*": "" //yields the value of the attribute without any wrapper
        }
      }
    }
  }
]

which returns 744659 as result for the current case返回744659作为当前案例的结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM