1

I m having a file like:

{
        "account": "/system1/test", 
        "description": "", 
        "desired_state": "active", 
        "id": "f957e20c-0033-4523-9020-e31304401149",
        "status": "active", 
        "tags": [], 
        "time_audited": "2018-01-14T23:12:22Z", 
        "time_created": "2018-01-14T22:34:53Z", 
        "time_updated": null
}

When I try to get a value out as:

with_items: "{{orch_details.content|from_json|json_query('status')}}"

Everything is fine.

I want to extract several other values but I can't combine them to the json_query like:

with_items: "{{orch_details.content|from_json|json_query('status, account, description')}}"

What is wrong with my syntax?

techraf
  • 64,883
  • 27
  • 193
  • 198
Phil Di
  • 11
  • 1
  • 3
  • How about checking [the documentation](http://docs.ansible.com/ansible/latest/playbooks_filters.html#json-query-filter) before posting on SO? – techraf Jan 15 '18 at 00:13

1 Answers1

3

I think the comment is trying to point out that json_query uses JMESPath for the filters. You can read up a bit on it at http://jmespath.org/tutorial.html.

In your examples, you could do something like the following to get an array of the values:

with_items: "{{orch_details.content|from_json|json_query('[status, account, description]')}}"

Which would return:

[
  "active",
  "/system1/test",
  ""
]

Or if you want a new hash maybe:

with_items: "{{orch_details.content|from_json|json_query('{"status": status, "account": account, "desc": description]')}}"

Which would return:

{
  "status": "active",
  "account": "/system1/test",
  "desc": ""
}
Andy Shinn
  • 26,561
  • 8
  • 75
  • 93
  • Thanks Andy , your solution works fine, i m a newbie :( , the docs indeed shows something similar – Phil Di Jan 15 '18 at 09:29
  • The comment is trying to point out that questions on SO should show [research effort. A lot. An absurd amount.](https://meta.stackoverflow.com/a/261593/2947502) – techraf Jan 15 '18 at 11:58