【问题标题】:best way to store bunch of json files in to database将一堆 json 文件存储到数据库中的最佳方法
【发布时间】:2020-04-16 21:06:56
【问题描述】:

我有 26 个来自开源的 json 文件(它们对单词有含义)

他们被命名为a.json,b.json,c.json........z.json

我正在寻找关于如何使用flask sql alchemy /pythonic 方式将这些数据存储在数据库(MySQL)中的建议,以便数据如下:

{
    "a cappella": {
        "word": "a cappella",
        "wordset_id": "5feb6f679a",
        "meanings": [
            {
                "id": "492099d426",
                "def": "without musical accompaniment",
                "example": "they performed a cappella",
                "speech_part": "adverb"
            },
            {
                "id": "0bf8d49e2e",
                "def": "sung without instrumental accompaniment",
                "example": "they sang an a cappella Mass",
                "speech_part": "adjective"
            }
        ]
    },
    "A.D.": {
        "word": "A.D.",
        "wordset_id": "b7e9d406a0",
        "meanings": [
            {
                "id": "a7482f3e30",
                "def": "in the Christian era",
                "speech_part": "adverb",
                "synonyms": [
                    "AD"
                ]
            }
        ]
    },.........
}

是为整个数据创建一个表还是为每个 json 文件创建一个表?

任何指导链接都会很有帮助,TIA

【问题讨论】:

标签: python flask flask-sqlalchemy pymysql


【解决方案1】:

如果每个文件的结构不同,请节省您的精力并将它们放入文档数据库(例如 MongoDB)中。

如果 JSON 数据的结构对于每个“单词”(看起来确实如此)都相同,则提取数据并将其存储在表中:WordMeaningSynonym

这些表将键入word,或者您可以添加一个代理键:

Word: [word, wordset_id]
Meaning: [word, meaning_id, def, example, speech_part
Synonym: [word, synonym_word]

【讨论】:

  • 嘿,谢谢你的信息(让我明白要起草一些东西),有什么关于 mongo 的例子吗? ,我尝试过mysql的方法,但它是一个更多的过程
  • @Codenewbie - 有很多将 JSON 加载到 mongo 的示例,这里有一个:stackoverflow.com/questions/19441228/…
  • 谢谢@Tony,我刚买了一个,正在努力,我也会参考这个
猜你喜欢
  • 2018-06-11
  • 2012-12-21
  • 2011-09-07
  • 2019-08-22
  • 2011-06-26
  • 2015-11-02
  • 2023-04-08
  • 2011-06-09
  • 1970-01-01
相关资源
最近更新 更多