Skip to content

Instantly share code, notes, and snippets.

@pvillard31
Created September 6, 2017 21:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvillard31/7d88482f3f8d71c94e372a6d6f2e2362 to your computer and use it in GitHub Desktop.
Save pvillard31/7d88482f3f8d71c94e372a6d6f2e2362 to your computer and use it in GitHub Desktop.
import org.apache.commons.io.IOUtils
import java.nio.charset.*
import org.json.JSONObject;
import org.json.XML;
def flowFile = session.get()
if (!flowFile) return
flowFile = session.write(flowFile,
{ inputStream, outputStream ->
def text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
def xmlJSONObj = XML.toJSONObject(text);
def json = xmlJSONObj.toString();
outputStream.write(json.getBytes(StandardCharsets.UTF_8))
} as StreamCallback)
flowFile = session.putAttribute(flowFile, "mime.type", "application/json")
session.transfer(flowFile, ExecuteScript.REL_SUCCESS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment