def reorder_json(data, models, ordering_cond={}):
    output = []
    bucket = {}
    others = []

    for model in models:
        bucket[model] = []

    for object in data:
        if object['model'] in bucket.keys():
            bucket[object['model']].append(object)
        else:
            others.append(object)
    for model in models:
        if model in ordering_cond:
            bucket[model].sort(key=ordering_cond[model])
        output.extend(bucket[model])

    output.extend(others)
    return output
Reorders JSON (actually a list of model dicts).
dataset/ETHPy150Open davedash/django-fixture-magic/fixture_magic/utils.py/reorder_json