How can i apply JoltTransformation on the hole json flowfile without splitting it?

Viewed 51

The next flow file is an InvoqueHTTP response:

[
  {
    "name": "Rolf",
    "sur_name": "ramsfl"
  },
  {
    "name": "Jose",
    "sur_name": "maxim"
  },
  {
    "name": "Andrei",
    "sur_name": "alexo"
  }
]

I wanted to use JoltTransformation instead of (ReplaceText to find the "_" and change it by emptystring) ReplaceText is not the needed solution.

I created this JoltTransformation:

[
  {
    "operation": "shift",
    "spec": {
    "name":"name",
    "sur_name":"surname"
    }
  }
]

This jolttransformation solves the problem well but if the flowfile is splitted , if i pass it as it is it gives null.

2 Answers

Use a JoltTransformRecord processor:

  • Record Reader: JsonTreeReader
  • Record Writer: JsonRecordSetWriter
  • Jolt Transformation DSL: Chain
  • Jolt Specification:
[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*_*": "[&1].&(0,1)&(0,2)",
        "*": "[&1].&"
      }
    }
  }
]

Output Json

[
  {
    "name": "Rolf",
    "surname": "ramsfl"
  },
  {
    "name": "Jose",
    "surname": "maxim"
  },
  {
    "name": "Andrei",
    "surname": "alexo"
  }
]

Is this spec resolving your issue :

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "name": "[&1].name",
        "sur_name": "[&1].surname"
      }
    }
  }
]
Related