JSON to CSV or Spreadsheet

Thank you for using this wonderful product.
I want to convert JSON to CSV or spreadsheet.
How easy is it?
Or tell us if you have any tips or past topics.

Thanks, that is great to hear!

That is very easy. At least if it is flat data (so only one level). Here an example:

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      firstName: 'Jim',\n      lastName: 'Miller',\n    }\n  },\n  {\n    json: {\n      firstName: 'Kim',\n      lastName: 'Smith',\n    }\n  }\n];"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "operation": "toFile",
        "fileFormat": "csv",
        "options": {}
      },
      "name": "Spreadsheet File",
      "type": "n8n-nodes-base.spreadsheetFile",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Function": {
      "main": [
        [
          {
            "node": "Spreadsheet File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Thank you for the response.
If the level is deep, as in the sample, what should I do?

{
  "data": [
    {
      "amount": 10000,
      "comment": “abcde”,
      "created_at": "2020-03-02T14:21:59+09:00",
      "editable": false,
      "id": 9999999999,
      "input_by":,
      "status": applied, 
      "transacted_at": "2020-03-02T14:21:59+09:00",
      "user_id": 9999999,
      "category": {
        "id": 70700,
        "name": name
      },
      "shop": {
        "id": xxxxxxx,
        "name": "shop_name"
      },
      "project": {
        "id": 20999999,
        "name": project_name,
        "display_id": 20999999
     }
}

Exactly the same but you have to be aware that this kind of data can not be presented perfectly in spreadsheets. For that reason will all lower-level data fields be converted to use dot notation like “category.id”.

@jan before opening a new topic, just wanted to check with you…
Do we currently have a support to resolve expressions and return result in json format? This would be useful in many cases.
I can raise a PR for that if its not supported currently

As a generic rule, it is always best to start a new topic. Because even if it exists already, will other people, which have the same question, find the answer. Additionally, will it also make sure that the original topic really just contains the messages it should contain.

To your question. It depends. If you want a flat JSON, then you can simply use a Set-Node, as all data within n8n is JSON anyway. If it is a more complex structure, you can use the Function-Node as you can literally set in there everything you want.