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 Transform Structure

avatar
New Contributor

Hi, I'm trying to develop a Jolt Spec for the following transform:

JSON Input:

 

 

[
    {
        "randomkeyname1": "randomvalue1"
    },
    {
        "randomkeyname11": "randomvalue11",
        "randomkeyname22": "randomvalue22"
    },
    {
        "randomkeyname111": "randomvalue111",
        "randomkeyname222": "randomvalue222",
        "randomkeyname333": "randomvalue333"
    }
]

 

 


JSON Output:

 

 

[
    {
        "data": [
            {
                "key": "randomkeyname1",
                "value": "randomkeyvalue1"
            }
        ]
    },
    {
        "data": [
            {
                "key": "randomkeyname11",
                "value": "randomkeyvalue11"
            },
            {
                "key": "randomkeyname22",
                "value": "randomkeyvalue22"
            }
        ]
    },
    {
        "data": [
            {
                "key": "randomkeyname111",
                "value": "randomkeyvalue111"
            },
            {
                "key": "randomkeyname222",
                "value": "randomkeyvalue222"
            },
            {
                "key": "randomkeyname333",
                "value": "randomkeyvalue333"
            }
        ]
    }
]

 

 

 
I've tried many things but I'm newbie to this and didn't find anyone with similar issue.

The closest result that I managed to get was with the following Spec:

 

 

 

[{
  "operation": "shift",
  "spec": {
    "*": {
      "*": {
        "$": "data[#2].key",
        "@": "data[#2].value"
      }
    }
  }
}]

 

 

 

Which gave me the following output:

 

 

{
    "data" : [ {
      "key" : [ "randomkeyname1", "randomkeyname11", "randomkeyname111" ],
      "value" : [ "randomvalue1", "randomvalue11", "randomvalue111" ]
    }, {
      "key" : [ "randomkeyname22", "randomkeyname222" ],
      "value" : [ "randomvalue22", "randomvalue222" ]
    }, {
      "key" : "randomkeyname333",
      "value" : "randomvalue333"
    } ]
  }

 

 

 

Note: I don't know how many values, key names nor root level arrays I'm getting, is somewhat random.

 

I appreciate any help or ideas, thanks in advance!

1 ACCEPTED SOLUTION

avatar
New Contributor

Hi everyone, the following spec did the trick!

 

 

[{
  "operation": "shift",
  "spec": {
    "*": {
      "*": {
        "$": "[&2].data[#2].key",
        "@": "[&2].data[#2].value"
      }
    }
  }
}]

 

View solution in original post

2 REPLIES 2

avatar
New Contributor

Hi everyone, the following spec did the trick!

 

 

[{
  "operation": "shift",
  "spec": {
    "*": {
      "*": {
        "$": "[&2].data[#2].key",
        "@": "[&2].data[#2].value"
      }
    }
  }
}]

 

avatar
Community Manager

@Rarasinhoo  I'm happy to see you resolved your issue. Please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future. 

Screen Shot 2019-08-06 at 1.54.47 PM.pngmark as solution button

Keep the questions coming