Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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