Expression returning [object Object]

When I use the following expression:

return [{json:{test: $evaluateExpression($node["FileMaker Data API"].json["response"]["dataInfo"])}}]

I get the following result:

[
  {
    "test": "[object Object]"
  }
]

And this is the JSON data:

BTW, when I go one level deeper, so:

return [{json:{test: $evaluateExpression($node["FileMaker Data API"].json["response"]["dataInfo"]["database"])}}]

then I get a valid result:

[
  {
    "test": "Vitamines"
  }
]

Any idea what I might be doing wrong or what might be wrong with my data structure?

One step further … by adding typeof, I found out that [object Object] is actually a string …

[
  {
    "test": "string"
  }
]

I then tried to convert the string via .split(’’), […string], Array.from(string) and Object.assign([], string), but neither of these options seem to return the key value pairs that I’m looking for …

Have you tried JSON.parse()? That will convert a string to a JSON object and could be what you are after. Or the other way and doing JSON.stringify().

@Jon when I ad JSON.parse(…)

return [{json: {test: JSON.parse($evaluateExpression($node["FileMaker Data API"].json["response"]["dataInfo"]))}}]

I get the following error:

ERROR: Unexpected token o in JSON at position 1

SyntaxError: Unexpected token o in JSON at position 1
    at JSON.parse (<anonymous>)
    at /Applications/n8n.app/Contents/Resources/app/node_modules/n8n-nodes-base/dist/nodes/Function:7:28
    at /Applications/n8n.app/Contents/Resources/app/node_modules/n8n-nodes-base/dist/nodes/Function:12:2
    at BaseHandler.apply (/Applications/n8n.app/Contents/Resources/app/node_modules/vm2/lib/bridge.js:479:11)
    at NodeVM.run (/Applications/n8n.app/Contents/Resources/app/node_modules/vm2/lib/nodevm.js:425:23)
    at Object.execute (/Applications/n8n.app/Contents/Resources/app/node_modules/n8n-nodes-base/dist/nodes/Function/Function.node.js:95:31)
    at Workflow.runNode (/Applications/n8n.app/Contents/Resources/app/node_modules/n8n-workflow/dist/src/Workflow.js:526:37)
    at /Applications/n8n.app/Contents/Resources/app/node_modules/n8n-core/dist/src/WorkflowExecute.js:451:62

I have the same issue. I want to add the json data from the previous node, but if I just use $json it doesn’t work out… The next node tells me it’s not valid json :smiley:

This is how the expression evaluates in my Set parameter with expression.
image

Hey @leprodude,

What happens if you use {{JSON.stringify($json)}}?

4 Likes

@Jon then it works, but that would be way too easy. Joke aside, wtf man thanks, I tried JSON.parse but obviously it’s the other one. Was a long session and I was convinced I’m thinking about it the right way… Thanks and sorry for the stupidity on my part lol

1 Like