Create a JSON object to be used dynamically in the backend

There's a backend action that I need to pass to a field called "Document" in a module I recently created. This field requires a JSON object containing the necessary data for the service to be consumed.

I have a backend action that I need to pass to a field called "Document" in a module I recently created. This field requires a JSON object containing the necessary data for the service to be consumed.

Using a static JSON value works perfectly as shown in the image, but I need to create this JSON object dynamically because it has internal attributes that are a JSON array, so the data needs to be generated dynamically. The problem is that I've generated it using 'Group', 'SetValue', and 'Repeat' (for those that require a data array), but when I pass it to the value 'Documento NFe/NFCe (JSON)', it doesn't pass the JSON string, only the dynamically generated value in Wappler.

Exemple;
1st - in the image above it works
2nd - in the image below I created a JSON with the same content to test.

This action that starts in 'Group' creates the JSON (I tested only the action in the browser and in the browser it gives this result).

Then I put the value of 'Group Venda' inside the 'Documento' field.

However, when I execute the action, it stops at {{venda}} instead of the created JSON object.

I don't know if I'm doing it wrong or if it's a problem with the framework.

I ran a test using .toJSON(), loading the content into a setValue before sending it to the 'Document' field of the module, but even though it shows the conversion of the JSON object to JSON text in the console, it doesn't load the text into the field.

Console

 server-connect:app Executing action step setvalue +3ms
  server-connect:app options: { value: '{{venda.toJSON()}}' } +0ms
  server-connect:output venda_json: '{"ide":{"cUF":"35","natOp":"VENDA DE MERCADORIA","mod":"65","serie":"99","dhEmi":"","tpNF":"1","idDest":"1","cMunFG":"3502101","tpImp":"4","tpEmis":"1","tpAmb":"2","finNFe":"1","indFinal":"1","indPres":"1","procEmi":"0","verProc":"TAJ_API_NFE 1.0"},"emit":{"CNPJ":"17953171000138","xNome":"EMPRESA TESTE LTDA","xFant":"EMPRESA TESTE","enderEmit":{"xLgr":"Rua Paraiba","nro":"492","xCpl":"Sala C","xBairro":"Benfica","cMun":"3502101","xMun":"ANDRADINA","UF":"SP","CEP":"16900406","cPais":"1058","xPais":"BRASIL","fone":"1837221552"},"IE":"170059050117","IM":"","CRT":"4"},"det_list":[{"$":{"nItem":"1"},"prod":{"cProd":"003","cEAN":"SEM GTIN","xProd":"PRODUTO TESTE 3","NCM":"22030000","CFOP":"5102","uCom":"UN","qCom":"3.0000","vUnCom":"30.00","vProd":"90.00","cEANTrib":"SEM GTIN","uTrib":"UN","qTrib":"3.0000","vUnTrib":"30.00","indTot":"1"},"imposto":{"vTotTrib":0,"ICMS":{"ICMSSN102":{"orig":"0","CSOSN":"102"}},"PIS":{"PISOutr":{"CST":"99","vBC":0,"pPIS":0,"vPIS":0}},"COFINS":{"COFINSOutr":{"CST":"99","vBC":0,"pCOFINS":0,"vCOFINS":0}}}},{"$":{"nItem":"2"},"prod":{"cProd":"003","cEAN":"SEM GTIN","xProd":"PRODUTO TESTE 3","NCM":"22030000","CFOP":"5102","uCom":"UN","qCom":"3.0000","vUnCom":"30.00","vProd":"90.00","cEANTrib":"SEM GTIN","uTrib":"UN","qTrib":"3.0000","vUnTrib":"30.00","indTot":"1"},"imposto":{"vTotTrib":0,"ICMS":{"ICMSSN102":{"orig":"0","CSOSN":"102"}},"PIS":{"PISOutr":{"CST":"99","vBC":0,"pPIS":0,"vPIS":0}},"COFINS":{"COFINSOutr":{"CST":"99","vBC":0,"pCOFINS":0,"vCOFINS":0}}}},{"$":{"nItem":"3"},"prod":{"cProd":"003","cEAN":"SEM GTIN","xProd":"PRODUTO TESTE 3","NCM":"22030000","CFOP":"5102","uCom":"UN","qCom":"3.0000","vUnCom":"30.00","vProd":"90.00","cEANTrib":"SEM GTIN","uTrib":"UN","qTrib":"3.0000","vUnTrib":"30.00","indTot":"1"},"imposto":{"vTotTrib":0,"ICMS":{"ICMSSN102":{"orig":"0","CSOSN":"102"}},"PIS":{"PISOutr":{"CST":"99","vBC":0,"pPIS":0,"vPIS":0}},"COFINS":{"COFINSOutr":{"CST":"99","vBC":0,"pCOFINS":0,"vCOFINS":0}}}}],"total":{"ICMSTot":{"vBC":"0.00","vICMS":"0.00","vICMSDeson":"0.00","vFCP":"0.00","vBCST":"0.00","vST":"0.00","vFCPST":"0.00","vFCPSTRet":"0.00","vProd":"100.00","vFrete":"0.00","vSeg":"0.00","vDesc":"0.00","vII":"0.00","vIPI":"0.00","vIPIDevol":"0.00","vPIS":"0.00","vCOFINS":"0.00","vOutro":"0.00","vNF":"100.00"}},"transp":{"modFrete":"9"},"pag":{"detPag":[{"indPag":"0","tPag":"01","vPag":"100.00"}],"vTroco":"0"},"infAdic":{"infCpl":"DOCUMENTO EMITIDO EM AMBIENTE DE HOMOLOGACAO","infAdFisco":""}}' +3ms
  server-connect:app Executing action step wait +3ms
  server-connect:app options: { delay: 2000 } +0ms
  server-connect:output wait: undefined +2s
  server-connect:app Executing action step nfeEmitir +3s
  server-connect:app options: {
  server-connect:app   certPath: '/app/upload_privado/1.pfx',
  server-connect:app   certPassword: 123456,
  server-connect:app   idCSC: '000001',
  server-connect:app   CSC: 'd6887227-f5fb-40df-938a-3ee5992caf68',
  server-connect:app   geral: '{\n  "versao": "4.00",\n  "ambiente": "2",\n  "modelo": "65"\n}',
  server-connect:app   documento: '{{venda_json}}'
  server-connect:app } +1ms
  server-connect:output Error at venda: Error: JSON inválido em "documento". Erro: Expected property name or '}' in JSON at position 1
  server-connect:output     at safeJsonParse (/opt/node_app/extensions/server_connect/modules/nfeEmitir.js:68:13)
  server-connect:output     at App.nfeEmitir (/opt/node_app/extensions/server_connect/modules/nfeEmitir.js:359:24)
  server-connect:output     at App._exec (/opt/node_app/lib/core/app.js:760:49)
  server-connect:output     at App._exec (/opt/node_app/lib/core/app.js:726:20)
  server-connect:output     at async App.exec (/opt/node_app/lib/core/app.js:692:5)
  server-connect:output     at async App.define (/opt/node_app/lib/core/app.js:674:5) +526ms
Error: JSON inválido em "documento". Erro: Expected property name or '}' in JSON at position 1
    at safeJsonParse (/opt/node_app/extensions/server_connect/modules/nfeEmitir.js:68:13)

Can someone please help me? It's a project I'm stuck on at this point.

I solved the issue by adding this.parse(params) inside my custom module.

Before, I was using the parameters directly like this:

const documento = params.documento;

When calling the module from a Server Action using something like:

documento: "{{venda}}"

the value was arriving inside the module as the literal string "{{venda}}", because bindings are not automatically resolved inside custom modules.

To fix this, I changed the beginning of the function to:

const parsedParams = this.parse(params);

And then I started using:

parsedParams.documento
parsedParams.geral

instead of:

params.documento
params.geral

After that, all {{ }} bindings were properly resolved before the module logic runs, and the object started arriving correctly as a real JSON object instead of a string.

That fixed the problem completely.