0

I need to flatten this json folder structure to a table format using pandas. I have been trying for a while now but haven't been able to get it. I can't seem to get the json_normalize to work.

[
{
    "folderId": 0,
    "pid": 0,
    "path": "/All Traits",
    "parentFolderId": 0,
    "folderCount": 12,
    "subFolders": [
                    {
                        "folderId": 5098,
                        "pid": 0,
                        "path": "/All Traits/3rd-Party Data",
                        "parentFolderId": 0,
                        "folderCount": 0,
                        "subFolders": [],
                        "dataSourceId": 0,
                        "name": "3rd-Party Data"
                    },
                    {
                        "folderId": 671518,
                        "pid": 2343,
                        "path": "/All Traits/Analytics Traits",
                        "parentFolderId": 0,
                        "folderCount": 62,
                        "subFolders": [
                            {
                                "folderId": 766737,
                                "pid": 2343,
                                "path": "/All Traits/Analytics Traits/300000767",
                                "parentFolderId": 671518,
                                "folderCount": 6,
                                "subFolders": [
                                                {
                                                    "folderId": 872557,
                                                    "pid": 2343,
                                                    "path": "/All Traits/Analytics Traits/300000767/deltadeltamicrositedev",
                                                    "parentFolderId": 766737,
                                                    "folderCount": 0,
                                                    "subFolders": [],
                                                    "name": "deltadeltamicrositedev"
                                                }],
                                "name": "300000767"
                            },
                            {
                                "folderId": 766740,
                                "pid": 2343,
                                "path": "/All Traits/Analytics Traits/dalbadprod",
                                "parentFolderId": 671518,
                                "folderCount": 0,
                                "subFolders": [],
                                "name": "dalbadprod"
                            },
                            {
                                "folderId": 766743,
                                "pid": 2343,
                                "path": "/All Traits/Analytics Traits/dalchrome",
                                "parentFolderId": 671518,
                                "folderCount": 0,
                                "subFolders": [],
                                "name": "dalchrome"
                            }
                        ],
            "name": "Analytics Traits"
        }],
    "name": "All Traits"
}

]

Output path, dataSourceId, subFolders, parentFolderId, name, pid, folderCount, folderId

  • Would each folder be its own entry, in addition to appearing in the `sub_folders` column of another row? – AMC Feb 11 '20 at 16:01
  • provide an output example because this is ambiguous. – marcos Feb 11 '20 at 16:09
  • Does this answer your question? [store part of JSON object in pandas df](https://stackoverflow.com/questions/59886050/store-part-of-json-object-in-pandas-df) – Koralp Catalsakal Feb 11 '20 at 16:10
  • Thank you, Yes each level would be its own record in the table. path, dataSourceId, subFolders, parentFolderId, name, pid, folderCount, folderId "/All Traits",,,,,"All Traits",0,12,0 "/All Traits/3rd-Party Data,0,,0,"3rd-Party Data",0,0,5098 "/All Traits/Analytics Traits",,,0,"Analytics Traits",2343,62,671518 "/All Traits/Analytics Traits/300000767",,,671518,"300000767",2343,6,766737 ... – user12879429 Feb 11 '20 at 18:41

0 Answers0