Maykid
Maykid

Reputation: 517

How to make a JSON file new line delimited in NiFi?

So I'm working with a batch JSON file that could have over 2,000 variables within it, and I'm trying to make the JSON file into a new line delimited. For example, the JSON file I'm receiving is:

[
  {
    "Test1": 1,
    "Test2": 2,
    "Test3": 3
  },
  {
    "Test4": 4,
    "Test5": 5
  },
  {
    "Test6": 6,
    "Test7": 7,
    "Test8": 8
  },
  {
    "Test9": 9,
    "Test10": 10
  }
]

My end goal is the following:

{
  "Test1": 1,
  "Test2": 2,
  "Test3": 3
}
{
  "Test4": 4,
  "Test5": 5
}
{
  "Test6": 6,
  "Test7": 7,
  "Test8": 8
}
{
  "Test9": 9,
  "Test10": 10
}

As you can see for the final output there is no longer a square bracket or comma's that are separating other curly brackets. I figured out a way through a ReplaceText processor to get rid of the square brackets [ ] but I'm having trouble getting rid of the , between the curly brackets and making the file a new line delimited JSON file. I know there is a way to SplitJSON then do a MergeContent processor to make this work properly. I'm trying to see if there is another way of doing this without splitting the file up and merging it back together.

Any help on this would be greatly appreciated!!

Upvotes: 2

Views: 627

Answers (1)

yaprak
yaprak

Reputation: 547

If you want to do it with ReplaceText, after getting rid of brackets, replace },{ with }shift+enter{

enter image description here

Upvotes: 2

Related Questions