Can I escape '.' in JSON key names when converting them to labels?

I am unable to write a correct query in the Log browser to make grafana accept my JSON key names - for labeling - when they contain the ‘.’ (period) character.
I do understand that the period character’s normal use case is to lower the search on the JSON object tree, but I would like to know if there’s a way to work around it.

Let’s say my JSON looks like this:
{
"normalKeyNames: "labeling works correctly",
"key.with.periods": "labeling not working"
}

I tried the following things, none of which seem to be working (no labels created/found or direct error):
... | json newLabel="key.with.periods"
... | json newLabel="key\.with\.periods"
... | json newLabel=(backtick)key.with.periods(backtick)
... | json newLabel=(backtick)key\.with\.periods\(backtick)

I assume it is not a bug because if I allow all of the fields to be parsed automatically (| json without parameters), the label is correctly created.

Hey @ler0sq

You’re almost there!
Try this:

... | json newLabel=`["key.with.periods"]`

You can refer to the docs for more examples

Damn, that combination did not cross my mind. Thank you.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.