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!

Jolt Transformation - nested array to root object

avatar
Visitor

Having issues flattening the nested array in an array of objects back to its parent.

 

Given this JSON : 

 

[
  {
    "id": "13",
    "uom": "EA",
    "name": "pOne",
    "display_name": "displayOne",
    "brand": "brandOne",
    "categories": [
      {
        "level1": "cLevel1",
        "level2": "cLevel2"
      }
    ]
  },
  {
    "id": "87",
    "uom": "EA",
    "name": "pTwo",
    "display_name": "displayTwo",
    "brand": "brandTwo",
    "categories": [
      {
        "level1": "cLevel1",
        "level2": "cLevel2"
      }
    ]
  }
]

 

 

I want to transform to this:

 

[ {
  "pName" : "pOne",
  "pBrand" : "brandOne",
  "pVariant" : "displayOne",
  "pSku" : "13-EA-000",
  "categoryHierarchy" : "cLevel1/cLevel2"
}, {
  "pName" : "pTwo",
  "pBrand" : "brandTwo",
  "pVariant" : "displayTwo",
  "pSku" : "87-EA-000",
  "categoryHierarchy" : "cLevel1/cLevel2"
} ]

 

 

So far I have these specs:

 

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "productSku": "=concat(@(1,id),'-', @(1,uom),'-000')",
        "categories": {
          "*": {
            "category": "=concat(@(1,level1),'/', @(1,level2))"
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "name": "[&1].pName",
        "brand": "[&1].pBrand",
        "display_name": "[&1].pVariant",
        "productSku": "[&1].pSku",
        "categories": {
          "*": {
            "category": "[&1].categoryHierarchy"
          }
        }
      }
    }
 }
]

 


It is however putting ALL the category values into a single array in the first object in the list, rather than in each respective object:

 

[ {
  "pName" : "pOne",
  "pBrand" : "brandOne",
  "pVariant" : "displayOne",
  "pSku" : "13-EA-000",
  "categoryHierarchy" : [ "cLevel1/cLevel2", "cLevel1/cLevel2" ]
}, {
  "pName" : "pTwo",
  "pBrand" : "brandTwo",
  "pVariant" : "displayTwo",
  "pSku" : "87-EA-000"
} ]

 

 

What Am I missing?

 

Thank you 🙂

1 REPLY 1

avatar
New Member

 

You can try below spec

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "productSku": "=concat(@(1,id),'-', @(1,uom),'-000')",
        "categories": {
          "*": {
            "category": "=concat(@(1,level1),'/', @(1,level2))"
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "name": "[&1].pName",
        "brand": "[&1].pBrand",
        "display_name": "[&1].pVariant",
        "productSku": "[&1].pSku",
        "categories": {
          "*": {
            "category": "[#4].categoryHierarchy"
          }
        }
      }
    }
 }
 ]