Created 05-06-2021 04:40 AM
Good morning everybody,
I have the following JSON return:
{
"RegistrosRecebidos" : 1,
"RegistrosImportados" : 0,
"Erros" : [ "Erro registro 0: The statement has been terminated.\r\nString or binary data would be truncated in table 'Ober_HML.dbo.DB_WS_IMP_CLIENTE', column 'NOME_FANTASIA'. Truncated value: 'ADLER PELZER PERNAMBUCO IND. E COMERCIO '." ]
}
By default from our supplier, it comes with some formatting. That in Nifi gives the following error:
Follow my flow:
How can I do to solve this problem in Nifi?
I am trying to use ReplaceText for this but I have not been successful.
Thanks.
Created 05-07-2021 06:03 AM
@leandrolinof
The "EvaluateJsonPath" processor you shared has the configured destination as a FlowFile-Attribute and thus leaves the content of the FlowFile unchanged.
So if FlowFile Attribute is where you want this parsed output to reside, you could use "ExtractText" [1] as an alternative solution.
The used value here would be:
.*Erros":\[(.*)\].*
This has only 1 capture group which is for the content you are trying to extract. That content is then added to the FlowFile in a new FlowFile attribute based on the property name.
If you instead want to replace the content of your FlowFile with only the portion of the original content you are trying to extract, you could use the "ReplaceText" [2] processor.
The used Java regex "Search value" here would be:
(.*Erros":\[)(.*)(\].*$)
Which breaks source content into 3 capture groups so regex matches entire content and capture group 2 matches on the string output you are looking for.
So "Replacement Value" is simply set to "$2" so that entire content is replaced with just contents of capture group 2.
[1] http://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.13.2/org.apache...
If you found this help you with your question, please take a moment to login and click accept on this solution.
Thanks,
Matt
Created 05-06-2021 11:11 AM
@leandrolinof
The shared bulletin is being produced by the EvaluateJsonPath processor.
It may be helpful if you share your current ReplaceText processor configuration, sample input file (prior to ReplaceText), desired output file (post ReplaceText), and the configuration of your EvaluateJsonPath processor.
Use case details are also very helpful to understand what your end-to-end goal is here.
Thanks,
Matt
Created 05-07-2021 04:10 AM
@MattWho Thank you for your help,
This is all my flow:
I send a JSON like this :
{
"User": "user",
"Key": "ABC",
"Table": "Table",
"Rows": [
{
"CODIGO": 1,
"NOME": "ABC REPRESENTACOES LTDA",
"NOME_FANTASIA": "PEDRO LIMA",
"ENDERECO": "RUA SANTOS, 178",
"BAIRRO": "",
"CIDADE": "SAO PAULO",
"UF": "SP",
"CEP": "11008999",
"TELEFONE": "(11) 99887 1234",
"EMAIL": "pedro.lima@email.com",
"FUNCAO": "REPRESENTANTE",
"CODIGO_SUPERIOR": "",
"CNPJ": "",
"INSCRICAO_ESTADUAL": "",
"NRO_CONTRATO": "8918-A",
"NRO_REG_EMPREGADO": "",
"DATA_CONTRATACAO": "2018/06/28",
"DATA_DESLIGAMENTO": "",
"SITUACAO": "ATIVO",
"REGIAO": "SP"
}
]
}
And at some point the API called returns an error, that at some point I need to deal with in order to insert the error in our database. This error is expected in the HTTP response.
Follows the configuration of the processors:
ReplaceText =
EvaluateJsonPath =
This is Response Before Replace Text =
{"RegistrosRecebidos":1,"RegistrosImportados":0,"Erros":["Erro registro 0: The statement has been terminated.\r\nString or binary data would be truncated in table \u0027Ober_HML.dbo.DB_WS_IMP_CLIENTE\u0027, column \u0027NOME_FANTASIA\u0027. Truncated value: \u0027ADLER PELZER PERNAMBUCO IND. E COMERCIO \u0027."]}
What I need is to take the value of the "Errors" property and save it in my database, only when trying to do this with EvaluateJsonPath it returns the following error:
For this reason I am trying to use ReplaceText but also without success.
I don't know if I managed to be clear enough in my doubt.
Created 05-07-2021 06:03 AM
@leandrolinof
The "EvaluateJsonPath" processor you shared has the configured destination as a FlowFile-Attribute and thus leaves the content of the FlowFile unchanged.
So if FlowFile Attribute is where you want this parsed output to reside, you could use "ExtractText" [1] as an alternative solution.
The used value here would be:
.*Erros":\[(.*)\].*
This has only 1 capture group which is for the content you are trying to extract. That content is then added to the FlowFile in a new FlowFile attribute based on the property name.
If you instead want to replace the content of your FlowFile with only the portion of the original content you are trying to extract, you could use the "ReplaceText" [2] processor.
The used Java regex "Search value" here would be:
(.*Erros":\[)(.*)(\].*$)
Which breaks source content into 3 capture groups so regex matches entire content and capture group 2 matches on the string output you are looking for.
So "Replacement Value" is simply set to "$2" so that entire content is replaced with just contents of capture group 2.
[1] http://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.13.2/org.apache...
If you found this help you with your question, please take a moment to login and click accept on this solution.
Thanks,
Matt
Created 05-07-2021 11:02 AM
Thanks for the time available for my problem, the "ExtractText" worked perfectly for my case and the data was saved in my database.
Grateful.