0

I am pretty new to Streamsets and I finding it a little confusing and challenging to frame a JSON object inside my Groovy Evaluator object.

I need to frame the below JSON:

{
    "filter": "(equals(type,'my/specific/Type') and equals(attributes.number, '1234') and (equals(attributes.status,'ACTIVE'))",
    "max": 10
}

I have tried this:

import groovy.json.*

records = sdc.records
for (record in records) {
    try {
       event = "{"filter": "(equals(type,'my/specific/Type') and equals(attributes.number, '1234') and (equals(attributes.status,'ACTIVE'))","max": 10}"
       record.value = event

        // Write a record to the processor output
        sdc.output.write(record)
    } catch (e) {
        // Write a record to the error pipeline 
        sdc.log.error(e.toString(), e)
        sdc.error.write(record, e.toString())
    }
}

But I receive the below error:

SCRIPTING_03 - Script failed to compile: 'javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1076.groovy: 6: unexpected token: and @ line 6, column 59. uals(type,'my/specific/Type') and equals ^ 1 error '

Kindly help in resolving this.

Mike
  • 721
  • 1
  • 17
  • 44
  • Line `event = ...` has incorrect string value. – daggett Jul 28 '22 at 09:39
  • I can understand that !! :) What's the incorrect string and how to change it is my question about. – Mike Jul 28 '22 at 10:04
  • Use single quotes to wrap the string, IE `event = '{"filt....` instead of `event = "{"filt....` – tim_yates Jul 28 '22 at 10:06
  • Received this. `com.streamsets.pipeline.api.base.OnRecordErrorException: SCRIPTING_04 - Script sent record to error: groovy.lang.MissingPropertyException: No such property: configuration for class: Script1082 at com.streamsets.pipeline.stage.processor.scripting.ScriptingProcessorInitDestroyBindings$Err.write(ScriptingProcessorInitDestroyBindings.java:48) at com.streamsets.pipeline.stage.processor.scripting.ScriptingProcessorInitDestroyBindings$Err$write.call(Unknown Source)` – Mike Jul 28 '22 at 10:46

1 Answers1

0

It's not about JSON per se, but about escaping a double-quote character. Groovy nothing but Java + some syntactic sugar, so escaping a " character in Groovy is the same: use ", for example:

foo = "I use so called \"Groovy\" for that"
Roman
  • 238
  • 1
  • 14