Support Questions

Find answers, ask questions, and share your expertise

Transfom JSON with Jolt

Contributor

Hi all, I would like to change the name of objects and add values to the following JSON file.

[
  {
    "Ean": 4052269532309,
    "Bestand": 0
  },
  {
    "Ean": 4052269532316,
    "Bestand": 0
  },
  {
    "Ean": 4052269532323,
    "Bestand": 0
  }
]


The result of my specification is not what I expect.

JOLT Script:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "Ean": "gtin",
        "ean": "gtin",
        "EAN": "gtin",
        "EanCode": "gtin",
        "EAN-Code": "gtin",
        "EANCode": "gtin",
        "Ausdr1": "gtin",
        "Bestand": "qty",
        "Menge": "qty",
        "Stock": "qty",
        "stock": "qty",
        "Verfügbare Menge (Kennzahl)": "qty",
        "Verfügbare Menge": "qty"
      }
    }
  },
  {
    "operation": "modify-default-beta",
    "spec": {
      "update_date": "2022-11-03",
      "supplier_name": "demo",
      "file_name": "test"
    }
  }
]

I get this result:

{
  "gtin" : [ 4052269532309, 4052269532316, 4052269532323 ],
  "qty" : [ 0, 0, 0 ],
  "update_date" : "2022-11-03",
  "supplier_name" : "demo",
  "file_name" : "test"
}

 

I expect that:

[
  {
    "gtin": 4052269532309,
    "qty": 0,
    "update_date" : "2022-11-03",
    "supplier_name" : "demo",
    "file_name" : "test"
  },
  {
    "gtin": 4052269532316,
    "qty": 0,
    "update_date" : "2022-11-03",
    "supplier_name" : "demo",
    "file_name" : "test"
  },
  {
    "gtin": 4052269532323,
    ",
    "update_date" : "2022-11-03",
    "supplier_name" : "demo",
    "file_name" : "test"": 0,
    "update_date" : "2022-11-03",
    "supplier_name" : "demo",
    "file_name" : "test"
  }
]

Does anyone have an idea how I can customize it? Thanks for help

1 ACCEPTED SOLUTION

Rising Star

Try that:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "Ean": "[&1].gtin",
        "ean": "[&1].gtin",
        "EAN": "[&1].gtin",
        "EanCode": "[&1].gtin",
        "EAN-Code": "[&1].gtin",
        "EANCode": "[&1].gtin",
        "Ausdr1": "[&1].gtin",
        "Bestand": "[&1].qty",
        "Menge": "[&1].qty",
        "Stock": "[&1].qty",
        "stock": "[&1].qty",
        "Verfügbare Menge (Kennzahl)": "[&1].qty",
        "Verfügbare Menge": "[&1].qty"
      }
    }
  }, {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "update_date": "2022-11-03",
        "supplier_name": "demo",
        "file_name": "test"
      }
    }
  }
]

Greetings

View solution in original post

1 REPLY 1

Rising Star

Try that:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "Ean": "[&1].gtin",
        "ean": "[&1].gtin",
        "EAN": "[&1].gtin",
        "EanCode": "[&1].gtin",
        "EAN-Code": "[&1].gtin",
        "EANCode": "[&1].gtin",
        "Ausdr1": "[&1].gtin",
        "Bestand": "[&1].qty",
        "Menge": "[&1].qty",
        "Stock": "[&1].qty",
        "stock": "[&1].qty",
        "Verfügbare Menge (Kennzahl)": "[&1].qty",
        "Verfügbare Menge": "[&1].qty"
      }
    }
  }, {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "update_date": "2022-11-03",
        "supplier_name": "demo",
        "file_name": "test"
      }
    }
  }
]

Greetings