import json
import io
import csv


def csv_file_str_from_json(json_s, fieldnames):
    """return a csv file contents string from a json string that must be an array of objects"""
    instances = json.loads(json_s)
    if len(instances) == 0:
        return None
    out = io.StringIO()
    writer = csv.DictWriter(out, fieldnames=fieldnames, extrasaction='ignore', dialect='editor') 
    writer.writeheader()
    writer.writerows(instances)
    return out.getvalue()