簡體   English   中英

Python:如何從 python 中的 JSON 模式中檢索表名和相應的列名

[英]Python: How to retrieve table name and corresponding columns name from JSON schema in python

示例架構:

{
"CLASS_A" :  {
      "type": "object",
       "properties": {
           "CLASS_B": {
             "type": "array",
             "items": {
                 "type": "object",
                  "properties": {
                     "NAME1": {
                          "type":  "string",
                       },
                     "NAME2": {
                          "type":  "string",
                       },
                     "CLASS_C":  {
                          "type": "array",
                          "items": {
                              "type": "object",
                              "properties": {
                                   "NAME3": {
                                       "type":  "string",
                                    },
                                   "NAME4": {
                                       "type":  "string",
                                   },
                                   
                                },
                            },
                        },  
                    },  
                },
            },
        },
    },  
},  

CLASS_B 和 CLASS_C 是表名,NAME1 和 NAME2 是表 CLASS_B 的列名

我有一個大的 JSON 架構,大約有 600 個表....

我需要在一個地方自動檢索表名及其對應的列。

首先,您將其更改為帶有命令的字典

import json
with open('data.json') as json_file:
    data = json.load(json_file)

然后您將其作為字典閱讀:

data['CLASS_A']['properties']
...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM