简体   繁体   English

如何列出文件中的所有 JSON 键以识别数据库列名?

[英]How to list all JSON keys in a file to identify database column names?

I plan to use Python to load JSON into an SQLite database.我计划使用 Python 将 JSON 加载到 SQLite 数据库中。 Is there a way to list all of the keys from a JSON file (not from a string) using Python?有没有办法使用 Python 列出 JSON 文件(而不是字符串)中的所有键?

I want to determine what columns I will need/use in my SQLite table(s), without having to manually read the file and make a list.我想确定我需要/在我的 SQLite 表中使用哪些列,而无需手动读取文件并制作列表。 Something along the lines of INFORMATION_SCHEMA.COLUMNS in SQL Server, or the FINDALL in Python for XML.类似于 SQL Server 中的INFORMATION_SCHEMA.COLUMNS或 Python for XML 中的FINDALL

I'm not looking to use other technologies, I'm sticking to Python, JSON, and SQLite on purpose.我不打算使用其他技术,我故意坚持使用 Python、JSON 和 SQLite。

The following syntax produced the desired results:以下语法产生了预期的结果:

import json

with open('my-file.json') as file:
    data = json.load(file)

for i in data:
    print(i.keys())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM