cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Record keys to array

michael_altenhu
Dynatracer
Dynatracer

I use the `parse` command with KVP like this

data record(str = "name=\"john\"; age=33; city=\"Atlanta\"")
| parse str, "KVP{LD:key'='(LONG:valueLong | STRING:valueStr)'; '?}:person"

so the output will look like this

"records": [
{
"str": "name=\"john\"; age=33; city=\"Atlanta\"",
"person": {
"name": "john",
"age": "33",
"city": "Atlanta"
}
}
]

I would like to have only the keys of the person object, so I end up with a structure like this:

"records": [
{
"str": "name=\"john\"; age=33; city=\"Atlanta\"",
"keys": [ "name", "age", "city" ]
  }
]

So what the Python expression list(person.keys()) would do.

1 REPLY 1

sinisa_zubic
Dynatrace Champion
Dynatrace Champion

Hi @michael_altenhu 

You could use the array matcher to just extract the keys

data record(str = "name=\"john\"; age=33; city=\"Atlanta\"")
| parse str, """ARRAY{LD:i '=' LD (';'|' '|EOS)}{1,}:keys"""

and this would be the result

  "records": [
    {
      "str": "name=\"john\"; age=33; city=\"Atlanta\"",
      "keys": [
        "name",
        " age",
        " city"
      ]
    }

 

Best,
Sini

Featured Posts