0

What is the Jolt Spec for extracting data from nested list

I have been experimenting with apache nifi , I want to use joltransformation processor for parsing json flow file content ,but I am unable to parse nested list

Input JSON -

{
"posts": [
 {
   "network": "test",
   "photos": [
     {
       "a": 1.7722222222222221,
       "s": "https://a.com",
       "m": "https://b.com",
       "l": "https://ccccc.com"
     }
   ]
 },
 {
   "network": "test1",
   "photos": [
     {
       "a": 1.7722222222222221,
       "s": "https://d.com",
       "m": "https://e.com",
       "l": "https://fffff.com"
     }
   ]
 }
]
}

JOLT Transformation file -

[
{
 "operation": "shift",
 "spec": {
   "posts": {
     "*": {
       "network": "[&1].profile",
       "photos": { "0": { "l": "[&1].p" } }
     }
   }
 }
}
]

Expected Output -

[ 
 {
 "profile" : "test",
 "p" : "https://ccccc.com"
 }, 
 {
 "profile" : "test1",
 "p" : "https://fffff.com"
 }
]

Actual Output -

[ 
 {
 "profile" : "test",
 "p" : [ "https://ccccc.com", "https://ffffff.com" ]
 }, 
 {
 "profile" : "test1"
 }
]

Please help me , I am unable to figure out what I am doing wrong

Aadi
  • 154
  • 1
  • 2
  • 18

1 Answers1

0

You were close

[
  {
    "operation": "shift",
    "spec": {
      "posts": {
        "*": {
          "network": "[&1].profile",
          "photos": { 
            "0": { 
              "l": "[&3].p" 
             } 
           }
        }
      }
    }
  }
]

The [&3].p is the important part as that means the index is used from 3 levels up, which is the one from posts.

Matthew Warman
  • 3,234
  • 2
  • 23
  • 35