title: Ansible URI module post form-urlencoded JSON data
body: <p>I am trying to access an API using ansible URI module. If I set <code>tasks[0].uri.body.json_data: &lt;literal string&gt;</code> it works, however, when I'm trying to inject variable into <code>tasks[0].uri.body.json_data: &lt;string with variable value injected&gt;</code>, it displays the following error
  <a href="https://i.stack.imgur.com/HzFtX.png" rel="nofollow noreferrer">json format error</a>.</p>
  <p>I'm just wondering how to inject the variable value in this case.</p>
  <p>Thank you in advance.</p>
  <p>Example code below</p>
  <pre><code>$ ansible-playbook test.yaml --extra-var id=1
  ---
  # test.yaml
  - name: Get person
    hosts: localhost
    vars:
      person_id: '{{ id }}'
    tasks:
    - name: Get person based on ID
      uri:
        url: https://example.com/api
        method: POST
        body_format: form-urlencoded
        validate_certs: no
        # return_content: yes
        body:
          auth_user: test
          auth_pwd: test
          json_data: '{&quot;operation&quot;: &quot;core/get&quot;, &quot;class&quot;: &quot;Person&quot;, &quot;key&quot;: &quot;{{person_id}}&quot;, &quot;output_fields&quot;: &quot;*&quot;}' # NOT working (replaced &quot;key&quot;: &quot;1&quot; with &quot;key&quot;: &quot;{{person_id}}&quot;)
          # json_data: '{&quot;operation&quot;: &quot;core/get&quot;, &quot;class&quot;: &quot;Person&quot;, &quot;key&quot;: &quot;1&quot;, &quot;output_fields&quot;: &quot;*&quot;}' # WORKING
      register: login
    - debug:
        var: person_id
    - debug:
        var: login.json
  </code></pre>