How do I create JSON output?
I need to create a field that is JSON in my SDC pipeline. How do I do that?
You can do this in a Jython evaluator with json.dumps()
. Just be sure to use record.value
rather than plain record
. You can also pass a field rather than the whole record:
import json
for record in records:
try:
# Whole record
record.value['json'] = json.dumps(record.value)
# Just a field
record.value['json_address'] = json.dumps(record.value['address'])
output.write(record)
except Exception as e:
# Send record to error
error.write(record, str(e))
This results in output like:
Asked: 2017-07-06 10:47:01 -0600
Seen: 358 times
Last updated: Jul 06 '17