<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def extract(ctx, input, output):
 """Run ChemDataExtractor on a document."""

    log.info('chemdataextractor.extract')
    log.info('Reading %s' % input.name)
    doc = Document.from_file(input, fname=input.name)
    records = [record.serialize(primitive=True) for record in doc.records]
    jsonstring = json.dumps(records, indent=2, ensure_ascii=False)
    output.write(jsonstring)