Convert JSON to JSONL in API Gateway velocity mapping template

367 views Asked by At

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.

1

There are 1 answers

0
Claude Brisson On

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