简体   繁体   中英

Jolt transformation for extracting data from nested list

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM