2017-09-21 3 views
1

Ich bin ein Neuling auf Apache Nifi und habe folgendes Problem: Ich möchte eine JSON-Datei zu transformieren, wie folgt: Von:aktualisieren Json-Attribute in Apache-Nifi: Jolt

{ 
    "Property1": "x1", 
    "Property2": "Tag_**2ABC**", 
    "Property3": "x3", 
    "Property4": "x4" 
    } 

zu:

{ 
    "**2ABC**_Property1": "x1", 
    "**2ABC**_Property3": "x3", 
    "**2ABC**_Property4": "x4" 
    }, 

bedeutet: den Wert von einem bestimmten Attribut nehmen, um alle anderen Attribute zu aktualisieren. Ich könnte Beispiele finden mit JoltTransformer-Prozessor, der gut funktioniert, wenn das Update nur eine Zeichenfolge hinzufügt. Aber nicht für meinen Fall Was ich bis jetzt getan habe: Ich habe jedes Attribut mit evaluateJSONPath Prozessor festgelegt. Aber ich habe gerade eine Menge Möglichkeiten ausprobiert, um den Update-Attribut-Prozessor zu verwenden, um es ohne Erfolg zu machen. Alle meine möglichen Tests sah aus wie (innerhalb UpdateAttribute):

Property1 --> ${'Property2':substring(4,6)}"_"${'Property1'} 

Mit Jolt:

[ 
{"operation": "modify-overwrite-beta", 
    "spec": { 
     "Property1": "${'Property2':substring(4,6)}_${'Property1'}" 
      } 
} 
] 

welchem ​​Punkt bin ich abhanden hier? Danke im Voraus!

Antwort

1

Ich weiß nicht über Nifi, aber hier ist, wie Sie es in Jolt tun können.

Spec

[ 
    { 
    "operation": "shift", 
    "spec": { 
     // match Property2 
     "Property2": { 
     "Tag_*": { // capture the nasty "**2ABC**" part to reference later 
      // go back up the tree to the root 
      "@2": { 
      // match and ignore Property2 
      "Property2": null, 
      // 
      // match Property* and use it and the captured 
      // "prefix" to create the output key 
      // &(2,1) references the Tag_*, and pull off the "**2ABC**" part 
      "Property*": "&(2,1)_&" 
      } 
     } 
     } 
    } 
    } 
] 
+0

Ausgezeichnet danke! Hoffentlich akzeptiert das OP: NiFi akzeptiert alle Jolt-Spezifikationen, muss nur "Shift" wählen und dann in Milos Spezifikation einfügen :) – mattyb

+0

Großartig! Danke Millionen dafür! Mein Wochenende gemacht .... – MDS

Verwandte Themen