MySQL JSON Column type

Hi guys,

I have a http service that return the JSON data, and I have mysql json column type, how to persist this data as json in json column type?

Hey @Ivanir_Broinizi!

Welcome to the n8n community! :slightly_smiling_face:

You can the Query operation to and write a query to add the value. You will have to select the JSON value through an expression. Below is an example workflow that might help. I am using a Webhook node to get the JSON data from a webhook request. I am then using the Function node to transform the data received from the Webhook node. And then in the MySQL node I am using a query to insert the data.

{
  "nodes": [
    {
      "parameters": {
        "path": "a32d09c3-1788-430c-ac68-b0b693b8cb40",
        "responseMode": "lastNode",
        "responseData": "allEntries",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        520,
        240
      ],
      "webhookId": "a32d09c3-1788-430c-ac68-b0b693b8cb40"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO `n8n-support`.`dummy`(`JSON_field`)\nVALUES('{{JSON.stringify($node[\"Function\"].json[\"JSON_field\"])}}')"
      },
      "name": "MySQL",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 1,
      "position": [
        940,
        240
      ],
      "credentials": {
        "mySql": "mysql-support"
      }
    },
    {
      "parameters": {
        "functionCode": "var json_field = items[0].json.body;\nreturn [{json:json_field}];"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        720,
        240
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "MySQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hope this helps. :slightly_smiling_face:

Thx @harshil1712

1 Like