Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

Transfom JSON with Jolt

avatar
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

avatar
Expert Contributor

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

avatar
Expert Contributor

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