# Ansible Automation Platform API Call Delivers Bad JSON Format

**URL:** <https://forum.ansible.com/t/ansible-automation-platform-api-call-delivers-bad-json-format/44532>\
**Category:** Get Help\
**Tags:** aap\
**Created:** [September 23, 2025, 7:40am UTC](https://forum.ansible.com/t/ansible-automation-platform-api-call-delivers-bad-json-format/44532 "2025-09-23T07:40:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![StefanSchnell](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/stefanschnell/32/9353_2.png) [@StefanSchnell](https://forum.ansible.com/u/StefanSchnell)\
**Post date:** [September 23, 2025, 7:40am UTC](https://forum.ansible.com/t/ansible-automation-platform-api-call-delivers-bad-json-format/44532/1 "2025-09-23T07:40:01Z")

</div>

Hello Community, 👋  
today I tried to call Ansible Automation Platform (AAP) release 2.5 API, e.g.

```auto
/api/controller/v2/job_templates/?page_size=100

```

However, calling json.loads with the response fails. The returned JSON has the following deviations from the standard:

- All strings are enclosed in single quotes instead of double quotes.
- All boolean values (True and False) are not enclosed in double quotes.
- All None values are also not enclosed in double quotes.

This causes json.loads to abort with an exception.

A month ago, the same Python source code worked without any problems.

In the header of the API call the content type is set to:

```auto
request.add_header("Content-Type", "application/json")

```

Is it possible to configure the JSON return format of API calls in the AAP?  
Or is there another way to get a valid JSON response?

Thanks for hints and tips.  
Best regards  
Stefan

---

<div class="post-metadata">

**Author:** ![StefanSchnell](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/stefanschnell/32/9353_2.png) [@StefanSchnell](https://forum.ansible.com/u/StefanSchnell)\
**Post date:** [September 28, 2025, 7:42am UTC](https://forum.ansible.com/t/ansible-automation-platform-api-call-delivers-bad-json-format/44532/2 "2025-09-28T07:42:28Z")

</div>

Hello Community,

I solved it on this way:

```auto
def jsonStringToDict(
    jsonString: str
) -> dict:

    jsonDict: dict = {}

    try:
        jsonDict = json.loads(jsonString)
    except:
        try:
            jsonDict = ast.literal_eval(jsonString)
        except Exception as err:
            raise Exception("An error occurred at JSON string to dictionary") from err

    return jsonDict

```

The first step is to try json.loads and, if it do not work, the second step is to try ast.literal\_eval. It works now as expected.

Best regards  
Stefan

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 28, 2025, 7:42am UTC](https://forum.ansible.com/t/ansible-automation-platform-api-call-delivers-bad-json-format/44532/3 "2025-10-28T07:42:45Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
