# JSON formatting error confusion

**URL:** <https://forum.inductiveautomation.com/t/json-formatting-error-confusion/85586>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [February 12, 2024, 8:06pm UTC](https://forum.inductiveautomation.com/t/json-formatting-error-confusion/85586 "2024-02-12T20:06:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cameron\_Nickle](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@Cameron\_Nickle](https://forum.inductiveautomation.com/u/Cameron_Nickle)\
**Post date:** [February 12, 2024, 8:06pm UTC](https://forum.inductiveautomation.com/t/json-formatting-error-confusion/85586/1 "2024-02-12T20:06:12Z")

</div>

Hi all!

I'm currently working on making API calls to an AXIS camera using ignition scripting and have been trying to understand the following error for a little bit now and cannot make heads nor tails of it.

The script(s) are:

```auto
import httplib
import urllib2
import urllib
import json

headers = {
"Content-type": "application/json", 
"Accept": "application/json,text,raw", 
"apiVersion": "1.0",
"method": "getApiList",
"params": {
    "id": "api-discovery"
    }
}
url = "http:// ***server*** /axis-cgi/streamprofile.cgi"
password = urllib2.HTTPPasswordMgrWithDefaultRealm()
password.add_password(None, url, " ***username***", " ***password***")
handler = urllib2.HTTPDigestAuthHandler(password)
opener = urllib2.build_opener(handler)
response = opener.open(url, headers)

data = json.load(response)   
data = json.dumps(data)
print data

or 

data = urllib.urlencode({'q': 'Status'})
h = httplib.HTTPConnection(' ***server***')
headers = {
"Content-type": "application/json", 
"Accept": "application/json,text,raw", 
"apiVersion": "1.0",
"method": "getSupportedVersions",
"params": {
    "id": "api-discovery"
    }
}
u = urllib2.urlopen('http:// ***server*** /axis-cgi/apidiscovery.cgi?', data)
h.request('POST', '/axis-cgi/apidiscovery.cgi?', data, headers)
r = h.getresponse()
print r.read()

```

The error is (depending if I call user or general system):

```auto
{"error": {"code": 2001, "message": "There was an 2001 error"}}

or

{"apiVersion": "1.1", "error": {"code": 4000, "message": "JSON syntax error on line 1: '[' or '{' expected near 'q'"}}

```

which is:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/3/b311dff06aa9457b4eb83769bf00731839b8b72f.png)

or

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/1/81aef33695705ee7ed81b3e5150a002f199cb622.png)

You'll notice that both of these errors are JSON formatting but I can't seem to fix this issue with attempting to correct the formatting or adding things to the Header call. Whats stranger is the JSON is directly off the AXIS page with minor changes to values of the key/value pairs.

If anyone has some insight into what I'm doing wrong that would be greatly appreciated as I'm fairly new to working with API's of this sort.

Thank you,

Cam

P.S - Any recommendations on how to work with these in a more comprehensive and streamline manner would also be greatly appreciated

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [March 11, 2024, 4:41am UTC](https://forum.inductiveautomation.com/t/json-formatting-error-confusion/85586/2 "2024-03-11T04:41:52Z")

</div>

What do the print statements in your code reveal?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 11, 2024, 8:10am UTC](https://forum.inductiveautomation.com/t/json-formatting-error-confusion/85586/3 "2024-03-11T08:10:16Z")

</div>

Try with ignition's built-ins:

> **[system.net.httpClient | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-net/system-net-httpClient)**
>
> Provides a general use object that can be used to send and receive HTTP requests.

see if it makes a difference.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 11, 2024, 12:06pm UTC](https://forum.inductiveautomation.com/t/json-formatting-error-confusion/85586/4 "2024-03-11T12:06:28Z")

</div>

I think we ended up figuring this out here: [Strange return on an AXIS camera API call - #17 by Cameron\_Nickle](https://forum.inductiveautomation.com/t/strange-return-on-an-axis-camera-api-call/86116/17)
