Need help with JSON comparison

Describe the question

I wanted to keep track of new versions of Minecraft using n8n. Right now I’m using python code that just compares all the json, but I’d like to move the entire workflow to n8n.
I would like to compare the previous version of json saved on disk with the new version received by the HTTP request, and eventually get a list of the new versions. An example of the response I would like to receive:

[
      {
        "id": "1.21",
        "type": "release",
        "url": "https://piston-meta.mojang.com/v1/packages/177e49d3233cb6eac42f0495c0a48e719870c2ae/1.21.json",
        "time": "2024-06-13T08:32:38+00:00",
        "releaseTime": "2024-06-13T08:24:03+00:00",
        "sha1": "177e49d3233cb6eac42f0495c0a48e719870c2ae",
        "complianceLevel": 1
      },
      {
        "id": "1.21-rc1",
        "type": "snapshot",
        "url": "https://piston-meta.mojang.com/v1/packages/47f1581b8feaa3fdf73f9b90e4afb7c2a1de1894/1.21-rc1.json",
        "time": "2024-06-13T08:15:30+00:00",
        "releaseTime": "2024-06-10T12:24:08+00:00",
        "sha1": "47f1581b8feaa3fdf73f9b90e4afb7c2a1de1894",
        "complianceLevel": 1
      }
]

I tried to compare it somehow, but I have only “In A only” and “In B only” output, as if there are completely different data. I tried to play around with different fields for comparison, but also didn’t get the results.

Please share your workflow

In Edit Field node: { "latest": { "release": "1.20.6", "snapshot": "1.21-rc - Pastebin.com

  • n8n version: 1.44.1 self hosted
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default maybe
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Ubuntu 20.04

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:

@shandydev , I would suggest to make the following changes to your workflow to be able to compare the versions:

  1. Add “Split Out” nodes to each branch to get only the versions
  2. Amend “Compare Datasets” to check id (which represents the version in each item in the versions data set).

Something like this

NOTE: The “HTTP Request” node returns the data in the form

{
  "latest": {
    "release": "1.21",
    "snapshot": "1.21"
  },
  "versions": [
    {
      "id": "1.21",
      "type": "release",
      "url": "https://piston-meta.mojang.com/v1/packages/177e49d3233cb6eac42f0495c0a48e719870c2ae/1.21.json",
      "time": "2024-06-13T08:32:38+00:00",
      "releaseTime": "2024-06-13T08:24:03+00:00",
      "sha1": "177e49d3233cb6eac42f0495c0a48e719870c2ae",
      "complianceLevel": 1
    },
    {
      "id": "1.21-rc1",
      "type": "snapshot",
      "url": "https://piston-meta.mojang.com/v1/packages/47f1581b8feaa3fdf73f9b90e4afb7c2a1de1894/1.21-rc1.json",
      "time": "2024-06-13T08:15:30+00:00",
      "releaseTime": "2024-06-10T12:24:08+00:00",
      "sha1": "47f1581b8feaa3fdf73f9b90e4afb7c2a1de1894",
      "complianceLevel": 1
    },
    . . .
  ]
}

To compare items in version with “Compare Datesets”, you need to split them out.

I assume the “Edit Fields” would have the data in the same format as the the one produced by “HTTP Request” node. If it is in the different format - for example, contains only the array of versions - then you would need to adjust the upper branch (remove “Split Out” node from there) or else to make sure you are truly comparing datasets.

2 Likes

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