<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def json_to_csv(json_input):
    '''
    Convert simple JSON to CSV
    Accepts a JSON string or JSON object
    '''
    try:
        json_input = json.loads(json_input)
    except:
        pass # If loads fails, it's probably already parsed
    headers = set()
    for json_row in json_input:
        headers.update(json_row.keys())

    csv_io = StringIO.StringIO()
    csv_out = csv.DictWriter(csv_io,headers)
    csv_out.writeheader()
    for json_row in json_input:
        csv_out.writerow(json_row)
    csv_io.seek(0)
    return csv_io.read()