有没有简单的方法生成这样一个JSON?我发现os.walk()
和os.listdir()
,所以我可以递归进入目录并构建一个Python对象,但它听起来像是重新发明轮子,也许有人知道完成此任务的可行代码吗?
{
"type": "directory",
"name": "hello",
"children": [
{
"type": "directory",
"name": "world",
"children": [
{
"type": "file",
"name": "one.txt"
},
{
"type": "file",
"name": "two.txt"
}
]
},
{
"type": "file",
"name": "README"
}
]
}