Basic Question about Jinja2 split

I’m trying to parse an entity into various elements. I’ve got everything before the dot and everything after the dot like this:

{% set my_test_json = {
  "x": 'timer.group_office_work_test',
} %}

{{ my_test_json.x.split('.')[0]}}
{{ my_test_json.x.split('.')[1]}}

That gives me the desired timer and `group_office_work_test’

How would I isolate the word after the dot and before the first underscore: e.g. group
And how would I isolate everything after the first underscore: e.g. office_work_test

Thanks, Richard

I think this will get you want you want…

{{ my_test_json.x.split('.')[1].split('_')[0] }}

1 Like
{% set my_test_json = {"x": 'timer.group_office_work_test'} %}

{% set y = my_test_json.x.split('.')[1].split('_', 1) %}

{{ y[0] }}
{{ y[1] }}

Is there a way to get office_work_test without defining a new variable?

I’m trying {{my_test_json.x.split('_', 1) }}

But that gives me ['', 'office_work_test']

Thanks, Richard

{{ my_test_json.x.split('.')[1].split('_', 1)[1] }}
1 Like

Thanks! That actually answers a lot of questions about the split command for me.

Cheers, Richard

1 Like