Json sytax error on code node

Describe the problem/error/question

Probably a stupid error but I cant seem to find what is the problem…

my previous node returns the json attached. My problem is that the first value of the “column_values” key can change depending on the item. To counter this I am trying to use jamespath query to always get the “value” of the item that has the “User” value to the “title” key.
To try this I am creating a code node that will return this JSON but when I paste the json I get a syntax error. I solved the quotes inside quotes problem with the \ but are still getting the syntax error on this part.

return [
{ “value”:
“{
"changed_at": "2023-11-06T14:54:07.407Z",
"linkedPulseIds":[{
"linkedPulseId":5393013653}]
}”
}
]

and can’t figure out why.

[
{
“id”: “5458908239”,
“name”: “Weber”,
“created_at”: “2023-11-06T14:53:53Z”,
“state”: “active”,
“column_values”: [
{
“id”: “subitems”,
“text”: “”,
“title”: “Subitems”,
“type”: “subtasks”,
“value”: null,
“additional_info”: null
},
{
“id”: “connect_boards4”,
“text”: “[email protected](A7124)”,
“title”: “User”,
“type”: “board-relation”,
“value”: “{"changed_at":"2023-11-06T14:54:07.407Z","linkedPulseIds":[{"linkedPulseId":5393013653}]}”,
“additional_info”: null
},
{
“id”: “mirror2”,
“text”: “2023-10-28 07:19”,
“title”: “Current Exp Date”,
“type”: “lookup”,
“value”: null,
“additional_info”: null
},
{
“id”: “status_1”,
“text”: “3 days”,
“title”: “Days Added”,
“type”: “color”,
“value”: “{"index":0,"post_id":null,"changed_at":"2023-11-06T14:54:10.307Z"}”,
“additional_info”: “{"label":"3 days","color":"#fdab3d","changed_at":"2023-11-06T14:54:10.307Z"}”
},
{
“id”: “button”,
“text”: “Click me”,
“title”: “Extend Expiration”,
“type”: “button”,
“value”: “{"clicks":1,"changed_at":"2023-11-06T14:54:11.008Z"}”,
“additional_info”: null
},
{
“id”: “status”,
“text”: “Working on it”,
“title”: “Status”,
“type”: “color”,
“value”: “{"index":0,"invalid":false,"changed_at":"2023-11-06T14:54:13.264Z"}”,
“additional_info”: “{"label":"Working on it","color":"#fdab3d","changed_at":"2023-11-06T14:54:13.264Z"}”
},
{
“id”: “creation_log”,
“text”: “2023-11-06 14:53:53 UTC”,
“title”: “Creation Log”,
“type”: “pulse-log”,
“value”: null,
“additional_info”: null
},
{
“id”: “date”,
“text”: “”,
“title”: “Old Exp Date”,
“type”: “date”,
“value”: null,
“additional_info”: null
},
{
“id”: “last_updated”,
“text”: “2023-11-06 14:54:13 UTC”,
“title”: “Last Updated”,
“type”: “pulse-updated”,
“value”: null,
“additional_info”: null
}
]
}
]

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version: Cloud 1.14.2
  • **Database (default: SQLite): postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @gariva
I don’t know much about jmspath, but a bit about javascript :wink:

here yo ufind the code for the code node which will return your userobject based on the array you provided. So it should be plug and play in your workflow.

const returnData = []

for (const item of $input.all()) {

  const user =  item.json.column_values.filter(item1 => item1.title === 'User')[0];

  user.value = JSON.parse(user.value)

  returnData.push(user);
}

return returnData;

The Problem is/was, that the value of the value property is interpreted as string. Thatswhy it is necessary to call JSOn.parse once.

Here is the workflow:

Cheers.

3 Likes

Thanks was super helpfull.

Regards
Gariva

1 Like

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