jmespath / jmespath.py

JMESPath is a query language for JSON.

Home Page:http://jmespath.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

setting the jmespath expr dynamically

pragyan019 opened this issue · comments

I am using jmespath as follows

data = { "value": [ { "datasetId": "cfafbeb1-8037-4d0c-896e-a46fb27ff229", "id": "5b218778-e7a5-4d73-8187-f10824047715", "name": "SalesMarketing2", "webUrl": "https://app.powerbi.com/groups/f089354e-8366-4e18-aea3-4cb4a3a50b48/reports/5b218778-e7a5-4d73-8187-f10824047715", "embedUrl": "https://app.powerbi.com/reportEmbed?reportId=5b218778-e7a5-4d73-8187-f10824047715&groupId=f089354e-8366-4e18-aea3-4cb4a3a50b48", }, { "datasetId": "cfafbeb1-8037-4d0c-896e-a46fb27ff229", "id": "5b218778-e7a5-4d73-8187-f10824047715", "name": "SalesMarketing3", "webUrl": "https://app.powerbi.com/groups/f089354e-8366-4e18-aea3-4cb4a3a50b48/reports/5b218778-e7a5-4d73-8187-f10824047715", "embedUrl": "https://app.powerbi.com/reportEmbed?reportId=5b218778-e7a5-4d73-8187-f10824047715&groupId=f089354e-8366-4e18-aea3-4cb4a3a50b48", }, ] }

And setting the jmespath expr dynamically as:
report= 'SalesMarketing3'
jmespath.search(f"'value[?name == {report}]'", data)
Instead of getting the dictionary corresponding to "SalesMarketing3", I am getting output as follows, Am I missing something?

'value[?name == SalesMarketing3]'

Any help is highly appreciated.

using the backtick worked , jmespath.search(f"value[?name == `{report}`]", data)