Splitting Values from JSON

Hi guys

I’ve scoured the forums for a solution to this and whilst I see lots of topics in relation to JSON, I can’t seem to find a solution that works for me - and I’m sure this should be straight forward with a regex type solution.

The JSON I need to extract the value from always follows the same structure:
{“ZbBind”:{“Device”:“0x1035”,“Status”:0,“StatusMessage”:“SUCCESS”}}

The only value I need to extract is the Device value, so 0X1035 in the above example.
Thanks all

Information on your n8n setup

Version 0.204.0
Self hosted on Digital Ocean Docker

Hi @mbuk, based on what you describe it seems like the Set node is the right fit for you. You can see an example below:

Hi
I’ve done as you describe but don’t get any results?

{
  "meta": {
    "instanceId": "13430cc8c4746822491278321fb5cf32374e1ff4e5e8ac13c3a1df5b155a52a5"
  },
  "nodes": [
    {
      "parameters": {
        "values": {
          "string": [
            {
              "value": "{\"ZbBind\":{\"Device\":\"0x1035\",\"Status\":0,\"StatusMessage\":\"SUCCESS\"}}"
            }
          ]
        },
        "options": {}
      },
      "id": "26c8c48a-3cd0-45d6-a725-58ab0dfe820e",
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        880,
        180
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "number": [
            {
              "name": "deviceValue",
              "value": "={{ $json.ZbBind.Device }}"
            }
          ]
        },
        "options": {}
      },
      "id": "47b23700-e16c-4ec5-b57e-ee3604c6e845",
      "name": "Set1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1100,
        180
      ]
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}```

Hi @mbuk, it looks in your example you aren’t working with a JSON object but a string inside a propertyName field. For @Niklas_Hatje’s logic to work you’d first need to parse this string. You can use JSON.parse() for the job.

I’ve updated your example workflow to show the idea:

This is the result:

Hope this helps!

1 Like

Hi

That’s great - thank you. Your solution worked, however when I tried to replicate it in my own workflow, the final set module couldn’t find a value from the previous input.

It wasn’t until a bit of trial and error that I noticed when pasting the JSON into the set module, my version was using a different quotation character:

Mine:

Yours:

It’s a subtle difference but enough for the workflow to not recognise the input!.

Thanks for your help here - really do appreciate it.

1 Like

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