Python 如何在2维中展平JSON,只能在1维中展平

Python 如何在2维中展平JSON,只能在1维中展平,python,json,flatten,Python,Json,Flatten,我们正在尝试在二维中展平json,但我们只能使用以下函数在一维中展平json,此函数返回二维中的json,但我们需要一个json数组,您可以创建一个包含多行(二维)的数据帧 我希望通过以下方式获得json数组: [{'id_oid': 'XXXXX', 'class': 'YYYYY', 'version': '1', 'array': 'value1', 'name': 'GVASDAD', 'code': 'V', 'level': 6, 'value': '0'}, {'id_oid':

我们正在尝试在二维中展平json,但我们只能使用以下函数在一维中展平json,此函数返回二维中的json,但我们需要一个json数组,您可以创建一个包含多行(二维)的数据帧

我希望通过以下方式获得json数组:

[{'id_oid': 'XXXXX',
'class': 'YYYYY',
'version': '1',
'array': 'value1',
'name': 'GVASDAD',
'code': 'V',
'level': 6,
'value': '0'},
{'id_oid': 'XXXXX',
'class': 'YYYYY',
'version': '1',
'array': 'value2',
'name': 'GVASDAD',
'code': 'V',
'level': 6,
'value': '0'},
{'id_oid': 'XXXXX',
'class': 'YYYYY',
'version': '1',
'array': 'value3',
'name': 'GVASDAD',
'code': 'V',
'level': 6,
'value': '0'},
{'id_oid': 'XXXXX',
'class': 'YYYYY',
'version': '1',
'array': 'value4',
'name': 'GVASDAD',
'code': 'V',
'level': 6,
'value': '0'}]
任何建议都会有帮助


提前感谢大家

我们可以得到一个示例输入吗?是的,您在代码中得到了示例,变量j包含将被展平的json,我得到的输出和我希望的输出,如果
{“key1”:“value1”}
中有多个键值对,会发生什么?而且,关键点重要吗?它不在示例输出中?如果数组中还有一个级别,如您所说,在数组中:{“key1”:[“k1”:“value1”,“k2”:“value2”]}我想垂直平铺这个级别为:{“key1_k1”:“value1”,“key1_k2”:“value2}
[{'id_oid': 'XXXXX',
'class': 'YYYYY',
'version': '1',
'array': 'value1',
'name': 'GVASDAD',
'code': 'V',
'level': 6,
'value': '0'},
{'id_oid': 'XXXXX',
'class': 'YYYYY',
'version': '1',
'array': 'value2',
'name': 'GVASDAD',
'code': 'V',
'level': 6,
'value': '0'},
{'id_oid': 'XXXXX',
'class': 'YYYYY',
'version': '1',
'array': 'value3',
'name': 'GVASDAD',
'code': 'V',
'level': 6,
'value': '0'},
{'id_oid': 'XXXXX',
'class': 'YYYYY',
'version': '1',
'array': 'value4',
'name': 'GVASDAD',
'code': 'V',
'level': 6,
'value': '0'}]