Json data manipulation with function

I am receiving some data via Webhook but the information is grouped

“body”: {

“data”: “{“retorno”:{“pedidos”:[{“pedido”:{“desconto”:“0,00”,“observacoes”:”",“observacaointerna”:"",“data”:“2021-12-08”,“numero”:“41”,“numeroOrdemCompra”:"",“vendedor”:"",“valorfrete”:“0.00”,“outrasdespesas”:“0.00”,“totalprodutos”:“39.90”,“totalvenda”:“39.90”,“situacao”:“Atendido”,“dataSaida”:“2021-12-08”,“loja”:“203298548”,“cliente”:{“id”:“4870766603”,“nome”:“Consumidor Final”,“cnpj”:null,“ie”:null,“rg”:"",“endereco”:null,“numero”:"",“complemento”:"",“cidade”:null,“bairro”:null,“cep”:null,“uf”:null,“email”:null,“celular”:null,“fone”:null},“pagamento”:{“categoria”:“Vendas (Gr\u00e1fica)”},“itens”:[{“item”:{“codigo”:"",“descricao”:“Impress\u00e3o Adesivo M\u00b2 Fosco”,“quantidade”:“1.0000”,“valorunidade”:“39.9000000000”,“precocusto”:null,“descontoItem”:“0.00”,“un”:“M\u00b2”,“pesoBruto”:“0.00000”,“largura”:“1”,“altura”:“1”,“profundidade”:"",“descricaoDetalhada”:"",“unidadeMedida”:“cm”,“gtin”:""}}],“parcelas”:[{“parcela”:{“idLancamento”:“15504385940”,“valor”:“39.90”,“dataVencimento”:“2021-12-08 00:00:00”,“obs”:"",“destino”:“3”,“forma_pagamento”:{“id”:“584666”,“descricao”:“Dinheiro”,“codigoFiscal”:“1”}}}]}}]}}"

}

I need the data to be returned this way in order to use the data

[image]

[

{

“retorno”: {

“pedidos”: [

{

“pedido”: {

“desconto”: “0,00”,

“observacoes”: “”,

“observacaointerna”: “”,

“data”: “2021-12-08”,

“numero”: “41”,

“numeroOrdemCompra”: “”,

“vendedor”: “”,

“valorfrete”: “0.00”,

“outrasdespesas”: “0.00”,

“totalprodutos”: “39.90”,

“totalvenda”: “39.90”,

“situacao”: “Atendido”,

“dataSaida”: “2021-12-08”,

“loja”: “203298548”,

“cliente”: {

“id”: “4870766603”,

“nome”: “Consumidor Final”,

“cnpj”: null,

“ie”: null,

“rg”: “”,

“endereco”: null,

“numero”: “”,

“complemento”: “”,

“cidade”: null,

“bairro”: null,

“cep”: null,

“uf”: null,

“email”: null,

“celular”: null,

“fone”: null

},

“pagamento”: {

“categoria”: “Vendas (Gráfica)”

},

“itens”: [

{

“item”: {

“codigo”: “”,

“descricao”: “Impressão Adesivo M² Fosco”,

“quantidade”: “1.0000”,

“valorunidade”: “39.9000000000”,

“precocusto”: null,

“descontoItem”: “0.00”,

“un”: “M²”,

“pesoBruto”: “0.00000”,

“largura”: “1”,

“altura”: “1”,

“profundidade”: “”,

“descricaoDetalhada”: “”,

“unidadeMedida”: “cm”,

“gtin”: “”

}

}

],

“parcelas”: [

{

“parcela”: {

“idLancamento”: “15504385940”,

“valor”: “39.90”,

“dataVencimento”: “2021-12-08 00:00:00”,

“obs”: “”,

“destino”: “3”,

“forma_pagamento”: {

“id”: “584666”,

“descricao”: “Dinheiro”,

“codigoFiscal”: “1”

}

}

}

]

}

}

]

}

}

]

I looked here for a way to remove the data via an array using a function, but unfortunately I can’t make it work

can you help me? Thank you very much

Hey @Rodrigo_Barbosa, this looks like the data is simply stringified. Would you be able to parse it using JSON.parse()? Here’s an example where I am using the Function Item node to do so:

Example Workflow

If that’s not what you’re looking for, could you share your code snippets in preformatted blocks? You can either use this button:

image

Or manually put three backticks ``` above and below your code snippets. This would prevent the forum from applying formatting to your code which makes it really hard to use it.

Thank you!

2 Likes

that was exactly it, thank you very much, it helped me a lot

[image]

1 Like

Glad to hear, thanks so much for confirming!

1 Like

Hello @MutedJam

I think I can use it in my case as well but I don’t now how to inport the data from the node before into the code.

Can you help?

The data I have comming from the webhook is:

[
{
"headers":
{
"x-real-ip":
"185.240.248.77",
"x-forwarded-for":
"185.240.248.77",
"host":
"warm-wasp-57.hooks.n8n.cloud",
"x-forwarded-proto":
"https",
"x-nginx-proxy":
"true",
"connection":
"close",
"user-agent":
"WordPress/6.1; https://hdr-it.com",
"accept":
"*/*",
"accept-encoding":
"deflate, gzip",
"referer":
"https://warm-wasp-57.hooks.n8n.cloud/webhook-test/0f59baec-440f-4ed9-91d0-3f203849ebeb?entries=%7B%22mf-nome%22%3A%22%5C%5Czx%5C%5Czx%22%2C%22mf-telephone%22%3A%22%5C%5Czx%5C%5Czx%22%7D&entry_id=&form_id=5700&version=3.0.1&file_uploads=null"
},
"params":
{
},
"query":
{
"entries":
"{"mf-nome":"peter","mf-telephone":"99999999"}",
"entry_id":
,
"form_id":
5700,
"version":
"3.0.1",
"file_uploads":
"null"
},
"body":
{
}
}
]

Olá @tray_corp utilize a função abaixo como no código a seguir

1 Like

Também me vi um pouco perdido no começo.
Recomendo-te pesquisares um pouco dentro aqui dos fóruns e estudar java script para se familiarizar com a linguagem do programa.

neste caso a sua função tem de ser selecionando a coluna de input, no caso do seu exemplo é a coluna data.
Pode clicar e arrastar a coluna para dentro do campo “value” ou inserir manualmente.

no seu caso isso deve funcionar
{{JSON.parse($json[“data”])}}

Hi all, sorry to jump on this, but may I kindly ask you to post in English here on the public forum? It’s very hard for others to follow the conversation otherwise.

We do have a designated Discord channel for chatting in Portuguese if you like and there’s always the DM option as well.

Thank you so much for your understanding!

2 Likes

I advise you to delete that image if it has actual email clients.

ok! mas enquanto minha duvida

Make your question in English so others can help or try the discord channel as said before.


i wanted to add this table to the left side to monday how do i link the columns

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.