Jolt : lookup value from another array

Viewed 119

I am trying to use the value of an element to lookup some other element. Then use one of the values of that other element in my output.

My Input:

 {
  "Sellprodukt" : [ {
    "Produkt" : [ {
      "name" : "ASV Water",
      "Elementarprodukt" : [ {
        "object" : [ {
          "companyID" : "3"    // use this value 3...
        } ]
      } ]

    }, {
      "name" : "ASV STORM",
      "Elementarprodukt" : [ {
        "object" : [ {
          "companyID" : "2"
        } ]
      } ]
    } ]
  } ],
  "Company" : [ {
    "type" : "CT_Companyplace",
    "GegenstandID" : "1_1",
    "Adress" : {
      "Street" : "Under the tree 32",
      "Postcode" : "12345",
      "Town" : "Forest",
      "Land" : "D"
    }
  }, {
    "type" : "CT_Company",
    "companyID" : "2",
    "contains" : [ {
      "companyID" : "1_1"
    } ],
    "companytype" : "Shop"
  }, {
    "type" : "CT_Company",
    "contains" : [ {
      "companyID" : "1_1"
    } ],
    "companyID" : "3",                // ...to find this 3
    "companytype" : "Bank"            // and use value Bank in output
  } ]

}

Desired output:

{
  "details" : {
    "cover" : [ {
      "name" : "ASV Water",
      "company" : {
        "type" : "Bank",
        "adress" :{
           THE ADRESS
         }
      }
    }, {
      "name" : "ASV STORM",
       "company" : {
        "type" : "Shop",
        "adress" :{
           THE OTHER ADRESS
         }
      }
    } ]
  }
}

With this spec I managed to get the companyID

[
  {
    "operation": "shift",
    "spec": {
      "Sellprodukt": {
        "*": {
          "Produkt": {
            "*": {
              "name": "details.cover[&1].name",
              "Elementarprodukt": {
                "*": {
                  "object": {
                    "*": {
                      "companyID": "details.cover[&5].companyID"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]

Now I have no idea how to get neither the "type" of the company or even the adres. Can somebody help? Or do I have to combine it later in java?

0 Answers
Related