0

I have an array of objects in JSON format coming in on the request. I would like to transform these objects into single line JSON (JSONL) in the velocity mapping template. Is this possible?

Going from:

[
 {
  "something": "else",
  "another": "thing"
 },
 {
  "something": "else",
  "another": "thing"
 }
]

Into

{ "something": "else", "another": "thing" }
{ "something": "else", "another": "thing" }

Any help would be much appreciated.

RobotEyes
  • 4,929
  • 6
  • 42
  • 57

1 Answers1

0

Something along those lines?

#foreach( $entry in $array )

  ## make sure $entry is a string
  #set( $entry = "$entry" )

  ## merge lines
  #set( $entry = $entry.replaceAll('\n', '') )

  ## print line
  $entry
#end
Claude Brisson
  • 4,085
  • 1
  • 22
  • 30