Search code examples
jsonazureazure-logic-appsazure-clijmespath

How do I list property names for an object using JMESPath?


I have a situation where the objects I am querying have unknown property names, and I would like to query the property names using JMESPath.

Here is an Azure CLI command and example output for it...Is there a way to get the names of the triggers without getting the value?

az logic workflow list --query "[].{name:name, triggers:definition.triggers}"
[
  {
    "name": "MyFirstLogicApp",
    "triggers": {
      "When_I_upload_a_new_video": {
        ...bunch of json...
      }
    }
  },
  {
    "name": "MySecondLogicApp",
    "triggers": {
      "When_an_S3_object_is_updated": {
        ...bunch of json...
      }
    }
  },
  {
    "name": "MyThirdLogicApp",
    "triggers": {
      "When_a_file_is_created_(properties_only)_(V2)": {
        ...bunch of json...
      }
    }
  },
  {
    "name": "MyFourthLogicApp",
    "triggers": {
      "When_a_file_is_modified_(properties_only)_(V2)": {
        ...bunch of json...
      }
    }
  }
]

Solution

  • Use the keys function to get only the keys of the provided object:

    az logic workflow list --query "[].{name:name, triggers:keys(definition.triggers)}"