Issue with ConvertFrom-Json

Trying to read a specific Json file from disc but the ConvertFrom-Json is not converting properly. Using old school powershell but same issue with pwsh (Core)

The json file on disc is the following :

[{    
    "pipeline_type": "WORKSPACE",
    "name": "Data Foundation Process",
    "clusters": [
        {
            "label": "default",
            "num_workers": 5
        }
    ],
    "libraries": [
        {
            "notebook": {
                "path": "//Shared//DataFoundation//Ingestion"
            }
        },
        {
            "notebook": {
                "path": "/Shared/DataFoundation/Transformation"
            }
        }
    ],
    "target": "DataFoundation",
    "continuous": false,
    "development": true,
    "photon": false,
    "edition": "ADVANCED",
    "channel": "CURRENT",
    "data_sampling": false
},
{    
    "pipeline_type": "WORKSPACE",
    "name": "Data Foundation Process 2",
    "clusters": [
        {
            "label": "default",
            "num_workers": 5
        }
    ],
    "libraries": [
        {
            "notebook": {
                "path": "/Shared/DataFoundation/Ingestion"
            }
        },
        {
            "notebook": {
                "path": "/Shared/DataFoundation/Transformation"
            }
        }
    ],
    "target": "DataFoundation",
    "continuous": false,
    "development": true,
    "photon": false,
    "edition": "ADVANCED",
    "channel": "CURRENT",
    "data_sampling": false
}
]

If you apply ConvertFrom-Json to it, it will screw up the path property of the notebooks in the libraries section. When you convert it back to json with ConvertTo-Json, it results in this

{
  "notebook":  "@{path=/Shared/DataFoundation/Ingestion}"
}

instead of this

{
     "notebook": {
            "path": "/Shared/DataFoundation/Ingestion"
      }
}

Any suggestions on how to avoid this? Tried the -AsHashtable approach but since we can have multiple objects in the array, this won’t work because I’m using a ForEach-Object to process each object as a whole.

Hi, welcome to the forum :wave:

Try changing the depth. A depth of 4 should work with your data:

$json | ConvertTo-Json -Depth 4
1 Like

I think it took longer to create the post then for you to solve it.
Thank youu very very much, you saved the bacon :wink:

1 Like