jmespath

Is there a query language for JSON which allow access to parent node and has multiselect?

送分小仙女□ 提交于 2019-12-11 02:42:47
问题 There are many query languages for JSON, such as JMES Path and JSON Path, but none of the ones I've found interest me, e.g. JSON Path doesn't allow multiselect query (I can't return a list with different type element [car, plane, boat]) and JMES Path is really simpler compare to the JSON Path and allow the multiselect but doesn't allow the access to the parent node like .. or parent(@) or $(for the source). So I want a language which can do both, if it's possible a query language simple as

JMESpath expression to filter object by property and return list of object names having this property set

喜夏-厌秋 提交于 2019-12-11 00:43:37
问题 Is it possible to write JMESPath expression to return a list of object names where a specific subproperty value is set? In the example below I'd like to get a list of all hostsnames where fileexists.stat.exists is set to true. My goal is to use Ansible hostvars structure to get a list of all hosts where a specific file is present. { "hostvars": { "oclab1n01.example.org": { "fileexists": { "changed": false, "failed": false, "stat": { "exists": false } } }, "oclab1n02.example.org": {

Ansible setting vars from with_items

守給你的承諾、 提交于 2019-12-10 09:57:39
问题 I am attempting to run a template task per ec2 instance, grabbing variables from other registered variables. The instance date is stored in ec2.tagged_instances, the IP information for the other two interfaces are stored in eni_dc and eni_spoke respectively. Debug example showing extraction of IP: - debug: msg: "{{ eni_dc.results|json_query(s_query) }}" vars: s_query: "[?interface.attachment.instance_id=='i-x].interface.private_ip_address" TASK [configure_vsrx : debug] ***********************

How to filter dictionaries in Jinja?

╄→гoц情女王★ 提交于 2019-12-09 13:07:18
问题 I have a dictionary of packages with package-name being the key and a dictionary of some details being the value : { "php7.1-readline": { "latest": "7.1.9-1+ubuntu14.04.1+deb.sury.org+1", "origins": [ "ppa.launchpad.net" ], "version": "7.1.6-2~ubuntu14.04.1+deb.sury.org+1", "www": "http://www.php.net/" }, "php7.1-xml": { "latest": "7.1.9-1+ubuntu14.04.1+deb.sury.org+1", "origins": [ "ppa.launchpad.net" ], "version": "7.1.6-2~ubuntu14.04.1+deb.sury.org+1", "www": "http://www.php.net/" },

JMESPath descend in tree for filter

。_饼干妹妹 提交于 2019-12-08 11:14:51
问题 What I'm trying to achieve I want to extract the volume ID for the root block device using describe-instances . What I tried so far aws ec2 describe-instances --filters "Name=tag:Backup,Values=True" --query 'Reservations[].Instances[].{Name: Tags[?Key==`Name`].Value | [0], Id: InstanceId, Block: BlockDeviceMappings[?DeviceName== RootDeviceName ].Ebs.VolumeId, Test: RootDeviceName}' What's not working Several things: Ebs.VolumeId is not the direct descendant of DeviceName , it is descending

ansible json-query path to select item by content

匆匆过客 提交于 2019-12-07 04:12:42
问题 Does anyone know what json-query filter can be used to select Tigger's food in the sample JSON below? The JSON is a simplified stand-in for a massive and relatively complicated AWS blob. Some background: I was rather pleased to discover that Ansible has a json-query filter. Given that I was trying to select an element from an AWS JSON blob this looked as if it was just what I needed. However I quickly ran into trouble because the AWS objects have tags and I needed to select items by tag. I

Dynamic/computed keys in JMESPath?

大城市里の小女人 提交于 2019-12-07 01:24:12
问题 From ES2015 with computed properties and Array.reduce/Array.map/Object.assign you can do: [{name: 'foo', age: 43}, {name: 'bar', age: 55}].map( o => ({[o.name]: o.age})).reduce((a, b) => Object.assign(a,b), {}) …and get: { foo: 43, bar: 55 } How do I get this from JMESPath? Attempt: $echo '[{"name": "foo", "age": 43}, {"name": "bar", "age": 55}]' | jp [].{name:age} [ { "name": 43 }, { "name": 55 } ] 回答1: Problem How to construct a Jmespath query that returns objects with arbitrary key-value

Ansible setting vars from with_items

给你一囗甜甜゛ 提交于 2019-12-06 01:13:35
I am attempting to run a template task per ec2 instance, grabbing variables from other registered variables. The instance date is stored in ec2.tagged_instances, the IP information for the other two interfaces are stored in eni_dc and eni_spoke respectively. Debug example showing extraction of IP: - debug: msg: "{{ eni_dc.results|json_query(s_query) }}" vars: s_query: "[?interface.attachment.instance_id=='i-x].interface.private_ip_address" TASK [configure_vsrx : debug] ********************************************************************** ok: [localhost] => { "changed": false, "msg": [ "10.24

ansible json-query path to select item by content

橙三吉。 提交于 2019-12-05 09:01:19
Does anyone know what json-query filter can be used to select Tigger's food in the sample JSON below? The JSON is a simplified stand-in for a massive and relatively complicated AWS blob. Some background: I was rather pleased to discover that Ansible has a json-query filter. Given that I was trying to select an element from an AWS JSON blob this looked as if it was just what I needed. However I quickly ran into trouble because the AWS objects have tags and I needed to select items by tag. I tried selector paths equivalent to Foods[Tags[(Key='For') & (Value='Tigger')]] and similar but didn't

Dynamic/computed keys in JMESPath?

≯℡__Kan透↙ 提交于 2019-12-05 05:09:13
From ES2015 with computed properties and Array.reduce / Array.map / Object.assign you can do: [{name: 'foo', age: 43}, {name: 'bar', age: 55}].map( o => ({[o.name]: o.age})).reduce((a, b) => Object.assign(a,b), {}) …and get: { foo: 43, bar: 55 } How do I get this from JMESPath? Attempt: $echo '[{"name": "foo", "age": 43}, {"name": "bar", "age": 55}]' | jp [].{name:age} [ { "name": 43 }, { "name": 55 } ] Problem How to construct a Jmespath query that returns objects with arbitrary key-value pairs The keys need to be dynamic, based on the output of a jmespath filter expression Workaround As of