title: Ansible Convert JSON to dictionary
body: <p>I have an HTTP endpoint that returns a JSON. Format below:</p>
  <pre><code>[
  {
      &quot;abbreviation_id&quot;: 1,
      &quot;FullName&quot;: &quot;Tiger&quot;,
      &quot;abbreviation&quot;: &quot;tig&quot;,
      &quot;active&quot;: true,
      &quot;createdDate&quot;: &quot;2021-01-25T06:17:32&quot;,
      &quot;modifiedDate&quot;: &quot;2021-01-25T06:17:32&quot;
  },
  {
      &quot;abbreviation_id&quot;: 69,
      &quot;FullName&quot;: &quot;Jaguar&quot;,
      &quot;abbreviation&quot;: &quot;jag&quot;,
      &quot;active&quot;: true,
      &quot;createdDate&quot;: &quot;2021-01-25T06:17:32&quot;,
      &quot;modifiedDate&quot;: &quot;2021-01-25T06:17:32&quot;
  }
  
  ]
  </code></pre>
  <p>After retrieving this, I have a var called {{ AnName }} and I would need to find its equivalent abbreviation from the JSON. I've been searching all day on how to do it so I tried to make a query for it with this code:</p>
  <pre><code>- name: Get abbreviation
    debug:
    var: item
    loop: &quot;{{ animal_lookups | community.general.json_query(abbreviation_query) }}&quot;
    vars: 
    abbreviation_query: &quot;animal_lookups[?FullName == {{ 
    AnName }}].abbreviation&quot;
  </code></pre>
  <p>But I realized I haven't installed community.general yet. Which leads me to ask if is this the best way to do it or is there a way for me to convert the JSON into a dictionary so I can do animal_lookups.AnName. Hopefully something like this:</p>
  <pre><code>animal_lookups:
  Tiger: tig
  Jaguar: jag
  </code></pre>
  <p>Thank you so much!</p>
  <p>UPDATE:: Tried Vladimir's solution but it seems like my animal_lookups is recognized as a dictionary, not a JSON.</p>
  <p>This code snippet displays the HTTP call that returns a JSON (shown below) and the task should convert is to a dictionary.</p>
  <pre><code> - name: Get Abbreviations
    uri:
     url: &quot;https://{{ function_name }}.azurewebsites.net/api/ListAnimals?code={{ function_code }}&quot;
     method: &quot;GET&quot;
     return_content: yes
     timeout: 60
     body_format: json
    register: animal_lookups
    no_log: &quot;{{ secure_logging }}&quot;
  
  - name: Convert JSON to dict
    set_fact:
     animal_dict: &quot;{{ animal_lookups|
                           items2dict(key_name='FullName',
                                      value_name='abbreviation') }}&quot;
  </code></pre>
  <p>In the logs it returns the JSON:</p>
  <pre><code> &quot;json&quot;: [
          {
              &quot;abbreviation&quot;: &quot;tig&quot;,
              &quot;active&quot;: true,
              &quot;cdl_abbreviation_id&quot;: 68,
              &quot;createdDate&quot;: &quot;2021-01-25T06:17:32&quot;,
              &quot;digitalSolution&quot;: &quot;Tiger&quot;,
              &quot;modifiedDate&quot;: &quot;2021-01-25T06:17:32&quot;
          },
          {
              &quot;abbreviation&quot;: &quot;jag&quot;,
              &quot;active&quot;: true,
              &quot;cdl_abbreviation_id&quot;: 69,
              &quot;createdDate&quot;: &quot;2021-01-25T06:17:32&quot;,
              &quot;digitalSolution&quot;: &quot;Jaguar&quot;,
              &quot;modifiedDate&quot;: &quot;2021-01-25T06:17:32&quot;
             }
         ]
  </code></pre>
  <p>but returns the error:</p>
  <pre><code>&quot;msg&quot;: &quot;items2dict requires a list, got &lt;class 'dict'&gt; instead.&quot;
  </code></pre>