Home > Blockchain >  Jolt transform add index to key
Jolt transform add index to key

Time:06-30

I'm trying to flatten a JSON file for SQL injestion. However, one of the levels is a date and therefore will not match my database (unless I create millions of fields). I need help please.

Original file:

[
  {
    "Transactions": {
      "Sales": {
        "2023-03-31": {
          "Item": "Monitor",
          "Manufacturer": "BenQ",
          "cost": "214.12",
          "currency": "Sterling"
        },
        "2023-03-30": {
          "Item": "Keyboard",
          "Manufacturer": "Dell",
          "cost": "14",
          "currency": "Sterling"
        },
        "2023-03-28": {
          "Item": "Laptop",
          "Manufacturer": "Acer",
          "cost": "840",
          "currency": "Sterling"
        }
      }
    }
  }
]

What I would like it to look like:

[
  {
    "Sale-1-item": "Monitor",
    "Sale-1-Manufacturer": "BenQ",
    "Sale-1-cost": "214.12",
    "Sale-1-currency": "Sterling"
    "Sale-2-Item": "Keyboard",
    "Sale-2-Manufacturer": "Dell",
    "Sale-2-cost": "14",
    "Sale-2-currency": "Sterling"
    "Sale-3-Item": "Laptop",
    "Sale-3-Manufacturer": "Acer",
    "Sale-3-cost": "840",
    "Sale-3-currency": "Sterling"
  }
]

Initially I tried using "Item" : "Item-&1" but this created chaos with items such as "Item-2023-03-01" which would need a column in my database for every day of the year! I then tried following the advice in enter image description here

  • Related