0

Suppose I have something like this:

    "config_service": {
        "config_service_1": {
            "service": "__service1__"
        },
        "config_service_2": {
            "service": "__service2__"
        }
    },

I am able to grab out the parent json by doing

$jsonMappings.config_service

But how can I dynamically iterate over each json value in there and do something like, for each object within config_service, extract value of key named 'service'? When I try doing ForEach-Object it treats the config service 1 and 2 as one big object.

m341
  • 19
  • 4
  • 1
    You can use the *intrinsic* property of `PSObject` that exposes those values under one property: `$json.config_service.PSObject.Properties.Value`. – Abraham Zinala Nov 29 '22 at 20:11
  • In short: Use `.psobject.Properties` to reflect on a given object's properties. The first linked duplicate shows how to do it for a single target object, the second shows how to walk an object graph recursively. – mklement0 Nov 29 '22 at 20:15

0 Answers0