How do I iterate over a JSON output and split out fields

I am trying to integrate Searxng, which provides an API with a JSON output for search.

I want to iterate through the JSON output without having to manually define each one, like a for loop in python.

Is there a node that can do this? I can’t seem to get the code note (python) to work (that’s probably a me thing as I don’t quite understand that integration yet)

Attached is the hard code way how to split out those fields, I need to loop over and change the - results[0].url programmatically if possible.

Thanks, for your help.

Here is some sample JSON output:

{
  "query": "what are the benefits of taurine",
  "number_of_results": 0,
  "results": [
    {
      "url": "https://health.clevelandclinic.org/taurine",
      "title": "Taurine Benefits and Side Effects",
      "content": "August 23, 2024 - She explains what taurine is, its risks and benefits and whether supplementation is a good idea. Taurine is an amino acid — that is, an organic compound used to make proteins. There are hundreds of amino acids that exist in nature, but only nine are essential for human life.",
      "thumbnail": "",
      "engine": "google",
      "parsed_url": [
        "https",
        "health.clevelandclinic.org",
        "/taurine",
        "",
        "",
        ""
      ],
      "template": "default.html",
      "engines": [
        "google",
        "qwant",
        "brave",
        "duckduckgo"
      ],
      "positions": [3, 3, 1, 1],
      "publishedDate": "2024-08-23T00:00:00",
      "score": 10.6666666666667,
      "category": "general"
    },
    {
      "url": "https://www.healthline.com/nutrition/what-is-taurine",
      "title": "What Is Taurine? Benefits, Side Effects, and More",
      "content": "February 28, 2023 - The anti-inflammatory effects of taurine may reduce inflammation within the brain and combat neurodegenerative conditions such as Alzheimer’s disease. May support liver health. Taurine may have protective effects against chronic and acute liver injury. Although promising, these potential ...",
      "thumbnail": "",
      "engine": "google",
      "parsed_url": [
        "https",
        "www.healthline.com",
        "/nutrition/what-is-taurine",
        "",
        "",
        ""
      ],
      "template": "default.html",
      "engines": [
        "google",
        "qwant",
        "brave",
        "duckduckgo"
      ],
      "positions": [1, 4, 2, 2],
      "publishedDate": "2023-02-28T00:00:00",
      "score": 9,
      "category": "general"
    },
  • n8n version: Version 1.64.3
  • Database (default: SQLite): Default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): Default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker local
  • Operating system: MacOS Sonoma

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:
1 Like

Added in the extra information.

Claude suggests this one liner. But I don’t quite understand the expression or code node yet:


urls = [result['url'] for result in json_data['results']]

I don’t know Javascript at all but it suggests something like:


const urls = data.results.map(({ url }) => url);

Any help or (even better) some pointers or links to tutorials/docs so I can understand how N8N uses expressions or nodes or the code node.

Welcome to the community @digitalkiwi !

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.

Make sure that you have removed any sensitive information from your workflow and include dummy or pinned data with it!


You need to name the array field to split out. In you case it will be just “results” in place of “results[0]…, results[1]…”