Ask Your Question
0

How do I create JSON output?

asked 2017-07-06 10:47:01 -0600

metadaddy gravatar image

I need to create a field that is JSON in my SDC pipeline. How do I do that?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-07-06 10:51:28 -0600

metadaddy gravatar image

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: Jython Preview

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-07-06 10:47:01 -0600

Seen: 312 times

Last updated: Jul 06 '17