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!

Generate Separate UUID for JSON array of objects

avatar
Explorer

Hi All,

 

I am trying to generate separate UUID for JSON array of objects. I tried to use ${UUID()} in JOLT specification, but this is generating same UUID for all the elements.

 

e.g.

Input:

===============

{
  "aliases": [
    "Alias1",
    " Alias2"
   ]
}

 

JOLT Specification

=====================

[
{
"operation": "shift",
"spec": {
"aliases": {
"*": "alias[&0].name"
}
}
},
{
"operation": "modify-default-beta",
"spec": {
"alias": {
"*": {
"id": "${UUID()}"
}
}
}
}
]
Current Output:

=====================

"alias" : [ {
"name" : "Alias1",
"id" : "2948446b-6213-44ba-b81f-c4e5f7dab2eb"
}, {
"name" : " Alias2",
"id" : "2948446b-6213-44ba-b81f-c4e5f7dab2eb"
} ]

 

Any pointers will be greatly appreciated.

 

Thanks,

Biswa 

1 ACCEPTED SOLUTION

avatar
Expert Contributor

Hi @Biswa!
I tried various ways of getting a unique id for each array. Most of them failed. But, I tried to append the array index to the unique id. Even while doing it, I faced many issues. See if the below spec is okay

[
{
"operation": "shift",
"spec": {
"aliases": {
"*": {
"@0": "alias[&1].name",
"$0": "alias[&1].id.${UUID()}-&1"
}
}
}
},
{
"operation": "shift",
"spec": {
"alias": {
"*": {
"id": {
"*": {
"$0": "alias[&3].id"
}
},
"*": "alias[&1].&"
}
}
}
}
] 

 

View solution in original post

1 REPLY 1

avatar
Expert Contributor

Hi @Biswa!
I tried various ways of getting a unique id for each array. Most of them failed. But, I tried to append the array index to the unique id. Even while doing it, I faced many issues. See if the below spec is okay

[
{
"operation": "shift",
"spec": {
"aliases": {
"*": {
"@0": "alias[&1].name",
"$0": "alias[&1].id.${UUID()}-&1"
}
}
}
},
{
"operation": "shift",
"spec": {
"alias": {
"*": {
"id": {
"*": {
"$0": "alias[&3].id"
}
},
"*": "alias[&1].&"
}
}
}
}
]