Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pkilambi
Created August 17, 2015 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkilambi/fc1c13d6081e2c3b04e7 to your computer and use it in GitHub Desktop.
Save pkilambi/fc1c13d6081e2c3b04e7 to your computer and use it in GitHub Desktop.
In [1]: import jsonpath
In [5]: foo = {'payload': {
u'metrics': [
{'timestamp': u'2013-07-29T06:51:34.472416',
'name': 'cpu.frequency', 'value': 1600,
'source': 'libvirt.LibvirtDriver'},
{'timestamp': u'2013-07-29T06:51:34.472416',
'name': 'cpu.user.time', 'value': 17421440000000,
'source': 'libvirt.LibvirtDriver'},]}}
In [11]: jsonpath.jsonpath(foo, 'payload.metrics.[?(@.name == "cpu.frequency")]')
Out[11]:
[{'name': 'cpu.frequency',
'source': 'libvirt.LibvirtDriver',
'timestamp': u'2013-07-29T06:51:34.472416',
'value': 1600}]
In [12]: jsonpath.jsonpath(foo, 'payload.metrics.[?(@.name == "cpu.frequency")].value')
Out[12]: [1600]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment