0

I need help with a JSON transformation. I'm using NIFI to transform a flat JSON into a nested JSON. I'm using processor JoltTransformJSON in version 1.8.0.

I have this JSON:

[
   {
      "territoryName":"Bauru",
      "territoryCode":"50",
      "territoryLatitude":1,
      "territoryLongitude":1,
      "branchCode":"80",
      "branchName":"Aracatuba",
      "branchLatitude":1,
      "branchLongitude":1
   },
   {
      "territoryName":"Bauru",
      "territoryCode":"50",
      "territoryLatitude":1,
      "territoryLongitude":1,
      "branchCode":"50",
      "branchName":"Bauru",
      "branchLatitude":1,
      "branchLongitude":1
   },
   {
      "territoryName":"Bauru",
      "territoryCode":"50",
      "territoryLatitude":1,
      "territoryLongitude":1,
      "branchCode":"74",
      "branchName":"Fernandopolis",
      "branchLatitude":1,
      "branchLongitude":1
   }
]

And I need an output like this

{
   "territoryName":"Bauru",
   "territoryCode":"50",
   "area":[
      {
         "latitude":1,
         "longitude":1
      },
      {
         "latitude":1,
         "longitude":1
      },
      {
         "latitude":1,
         "longitude":1
      }
   ],
   "branches":[
      {
         "branchName":"Aracatuba",
         "branchCode":"80",
         "area":[
            {
               "latitude":1,
               "longitude":1
            },
            {
               "latitude":1,
               "longitude":1
            }
         ]
      },
      {
         "branchName":"Bauru",
         "branchCode":"50",
         "area":[
            {
               "latitude":1,
               "longitude":1
            },
            {
               "latitude":1,
               "longitude":1
            }
         ]
      },
      {
         "branchName":"Fernandopolis",
         "branchCode":"74",
         "area":[
            {
               "latitude":1,
               "longitude":1
            },
            {
               "latitude":1,
               "longitude":1
            }
         ]
      }
   ]
}

I'm trying JOLT on line but I can't figure out how to create the spec to do it. Any help is welcome.

Michał Ziober
  • 37,175
  • 18
  • 99
  • 146
  • Do you have any example what exactly have you tried and where is the problem? – Michał Ziober Feb 15 '19 at 13:30
  • hi - this is the spec I'm using. It basically groups all the data on the same list. [ { "operation": "shift", "spec": { "*": { "territoryName": { "*": { "@(3,[&2])": "&.[]" } } } } }, { "operation": "shift", "spec": { "*": { "$": "&.name", "*": { "branchCode|branchName|branchLatitude|branchLongitude": "&4.&[]" } } } }, { "operation": "shift", "spec": { "*": "[#1]" } } ] – Rogério Barbosa Feb 15 '19 at 13:46
  • You can start from https://stackoverflow.com/questions/44674781/jolt-grouping-together – Michał Ziober Feb 15 '19 at 13:53
  • thanks, I will check it – Rogério Barbosa Feb 15 '19 at 14:00

0 Answers0