Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Parsing JSON in groovy evaluator

I was attempting to take events produced by the aggregator processor and parse them into JSON, with the ultimate goal of re-arranging the aggregation event data, splitting out separate events for each group-by element, and then inserting the aggregations into either a relational database or elasticsearch destination. The aggregation processor's events contain a string field containing what appears to be valid JSON representing the results of each aggregation executed by the processor. I first tried using the JSON parser processor on the record to convert it to JSON, but that resulted in an IllegalArgumentException (String field could not be converted to a map). So, I turned to using a groovy processor, in which I would use a JSONSlurper to process the aggregation event string, and then apply the logic to re-form the data and produce the derived events that I wanted. On a first pass, I have just the following in groovy script:

import groovy.json.*
import groovy.json.internal.*

for (record in records) {
    try {
        groovy.json.JsonSlurper slurper = new groovy.json.JsonSlurper()
        def result = slurper.parseText(record.value)
        log.info(new groovy.json.JsonBuilder(result).toPrettyString())
        output.write(record)
    } catch (e) {
        log.error(e.toString(), e)
        error.write(record, e.toString())
     }
}

At this point, the intention is just to prove out that I can slurp the aggregation event JSON data, and log it. But, I get:

java.lang.NoClassDefFoundError: Could not initialize class groovy.json.internal.JsonParserCharArray

So, my question is how I can go about parsing a JSON string to a JSON object in a groovy processor. Do I need to do something specific to introduce JsonParserCharArray into the class path? I was under the impression that class was part of the core groovy library.

Or, is there a completely different approach I should be taking to achieve my goal?