1

ファイルの大規模なバッチからいくつかのデータを抽出し、Django Fixtures を使用してデータベースにインポートするために特定の (JSON) 形式に変換しようとしています

私はこれまでに得ることができました:

'{ { {\n "pk":2,\n "model": trial.conditions,\n "fields": {\n "trial_id": NCT00109798,\n "keyword": 脳および中枢神経系腫瘍,\ n }{\n "pk":3,\n "model": trial.conditions,\n "fields": {\n "trial_id": NCT00109798,\n "keyword": リンパ腫,\n }{\n "pk": 2、\n "model": trial.criteria、\n "fields": {\n "trial_id": NCT00109798、\n "gender": 両方、\n "minimum_age": 18 歳、\n "maximum_age": 該当なし、\n "healthy_volunteers": いいえ、\n "textblock": ,\n }\n\t\t"pk":2,\n\t\t"モデル": trial.keyword,\n\t\t"フィールド": {\n\t\t"trial_id": NCT00109798,\n\t\t"キーワード": 原発性中枢神経系非ホジキンリンパ腫、\n\t\t}\n\t\t

...何行も後に.....

研究治療の完了後、患者は 3 か月ごとに 1 年間、\n4 か月ごとに 1 年間、その後 6 か月ごとに 3 年間追跡されます。 \n 、\n "overall_status": 募集中、\n "phase": フェーズ 2、\n "enrollment": 25、\n "study_type": 介入、\n "condition": 2,3 ,\n "基準": 1,\n "overall_contact": テストデータ,\n "場所": 4,\n "lastchanged_date": 2010 年 3 月 31 日,\n "firstreceived_date": 2005 年 5 月 3 日,\n " keyword": 2,3,\n "condition_mesh": ,\n }\n \n {\n "pk": testdata,\n "model": trial.contact,\n "fields": {\n "trial_id": NCT00109798,\n "last_name": Pamela Z. New, MD,\n "phone": ,\n "email": ,\n }}'

出力は実際には次のようになる必要があります。

{
    "pk": trial_id,
    "model": trials.trial,
    "fields": {
            "trial_id": trial_id,
            "brief_title": brief_title,
            "official_title": official_title,
            "brief_summary": brief_summary,
            "detailed_Description": detailed_description,
            "overall_status": overall_status,
            "phase": phase,
            "enrollment": enrollment,
            "study_type": study_type,
            "condition": _______________,
            "elligibility": elligibility,
            "criteria": ______________,
            "overall_contact": _______________,
            "location": ___________,
            "lastchanged_date": lastchanged_date,
            "firstreceived_date": firstreceived_date,
            "keyword": __________,
            "condition_mesh": condition_mesh,
    }

    "pk": null,
    "model": trials.locations,
    "fields": {
           "trials_id": trials_id,
           "facility": facility,
           "city": city,
           "state": state,
           "zip": zip,
           "country": country,
    }

アドバイスをいただければ幸いです。

4

2 に答える 2

1

json モジュールには pretty printer があります。このようなことを試してくださいprint json.dumps(s, indent=4)

>>> s = {'pk': 5678, 'model': 'trial model', 'fields': {'brief_title': 'a short title', 'trial_id':    1234}}

>>> print json.dumps(s, indent=4)
{
    "pk": 5678, 
    "model": "trial model", 
    "fields": {
        "brief_title": "a short title", 
        "trial_id": 1234
    }
}
于 2011-11-06T02:32:48.400 に答える