Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

NiFi - Need help with JOLT-Syntax JoltTransformJSON

SOLVED Go to solution
Highlighted

NiFi - Need help with JOLT-Syntax JoltTransformJSON

Rising Star

Hi, I need some help with JOLT-syntax.

JSON-Input

{
  "nummer": "1073",
  "table": [
    {
      "datum": "20180529",
      "zn": 1
    },
    {
      "datum": "20180530",
      "zn": 2
    },
    {
      "datum": "20190522",
      "zn": 3
    }
  ]
}


JOLT-Specification

[{
    "operation": "shift",
    "spec": {
      "nummer": "Nummer",
      "table": {
        "*": {
          "zn": "Positionen.[].ZeileNr",
          "datum": "Positionen.[].Datum"
        }
      }
    }
}
]


JSON-Output

{
    "Nummer": "1073",
    "Positionen": [{
        "ZeileNr": 1
    }, {
        "Datum": "20180529"
    }, {
        "ZeileNr": 2
    }, {
        "Datum": "20180530"
    }, {
        "ZeileNr": 3
    }, {
        "Datum": "20190522"
    }]
}

But the JSON-Output what I need is:


{
    "Nummer": "1073",
    "Positionen": [{
        "ZeileNr": 1,
        "Datum": "20180529"
    }, {
        "ZeileNr": 2,
        "Datum": "20180530"
    }, {
        "ZeileNr": 3,
        "Datum": "20190522"
    }]
}

Please, how can I manage this, it is driving me crazy...

Thanks for any help and information about this syntax!

1 ACCEPTED SOLUTION

Accepted Solutions

Re: NiFi - Need help with JOLT-Syntax JoltTransformJSON

You were so close! By using the [] syntax it just adds to the outgoing array, but you wanted to associate them with the same index, namely the one matched by the * "above" the fields. Put #2 inside your braces (#2 is a reference to the array index you're iterating over, "two levels up" from where you are in the spec):

[{
    "operation": "shift",
    "spec": {
      "nummer": "Nummer",
      "table": {
        "*": {
          "zn": "Positionen.[#2].ZeileNr",
          "datum": "Positionen.[#2].Datum"
        }
      }
    }
}]
1 REPLY 1

Re: NiFi - Need help with JOLT-Syntax JoltTransformJSON

You were so close! By using the [] syntax it just adds to the outgoing array, but you wanted to associate them with the same index, namely the one matched by the * "above" the fields. Put #2 inside your braces (#2 is a reference to the array index you're iterating over, "two levels up" from where you are in the spec):

[{
    "operation": "shift",
    "spec": {
      "nummer": "Nummer",
      "table": {
        "*": {
          "zn": "Positionen.[#2].ZeileNr",
          "datum": "Positionen.[#2].Datum"
        }
      }
    }
}]