Extracting Data from Nested JSON

How can I extract the Data from Nested JSON?
I’m my case. How can I extract just the text Test Value

Hey @mcnaveen!

Looks like the JSON object is parsed as a string and hence you are not able to directly get the value you want. You can use the Function node and convert the string back into a JSON object using the JSON.parse() method.

Here is an example workflow that might help

{
  "nodes": [
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "value_of_d",
              "value": "={{$node[\"Function1\"].json[\"new_value\"][\"field\"][\"d\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1030,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "items[0].json.myVariable = '{\"field\":{\"a\":1, \"b\":2, \"c\":3, \"d\":4}}';\nreturn items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        630,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "\n//items[0].json.myVariable = 1;\nreturn [{json:{new_value:JSON.parse(items[0].json.myVariable)}}];"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        830,
        300
      ]
    }
  ],
  "connections": {
    "Function": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thanks @harshil1712 It’s working

I am glad I was able to help. Have fun!

1 Like