If you have data in a nested table array you can convert it to the standard key:value JSONpair by using the below groovyscript.
Below is a sample of the data pre executing the groovy script. Note the column names in a JSON array value, and the values themselves in a nested array.

Script
import org.apache.commons.io.IOUtils
import java.nio.charset.StandardCharsets
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
import groovy.json.JsonBuilder
flowFile = session.get()
if(!flowFile)return
def text = ”
// Cast a closure with an inputStream parameter to InputStreamCallback
session.read(flowFile, {inputStream ->
text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
// Do something with text here
// def json = new JsonSlurper().parseText(text)
slurper = new JsonSlurper()
parsedJson = slurper.parseText(text)
columnNames = parsedJson.columns.name
valueRow = parsedJson.values
// Build key-value map
result = [:]
result2 = []
//ii=0
for (int ii = 0; ii < valueRow.size(); ii++) { item=valueRow[ii] columnNames.eachWithIndex { key, i ->
result[key] = item[i]
}
result2[ii] = result
//clear result array
result = [:]
}
} as InputStreamCallback)
try {
flowFile = session.write(flowFile, { inputStream, outputStream ->
// Write new content to the outputStream
outputStream.write(JsonOutput.prettyPrint(JsonOutput.toJson(result2)).getBytes(StandardCharsets.UTF_8))
} as StreamCallback)
session.transfer(flowFile, REL_SUCCESS)
} catch (e) {
// Log the error
log.error(“Error processing flow file: ” + e.getMessage())
session.transfer(flowFile, REL_FAILURE)
}
Once the script is executed the result is shown below as a standard key:value pair format
