Skip to content

Commit 08c1726

Browse files
authored
Merge pull request #10 from dhalbert/ujson-to-json
import either json or ujson
2 parents 7d37fe9 + 4f65676 commit 08c1726

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

adafruit_esp32spi/adafruit_esp32spi_requests.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ def text(self):
103103

104104
def json(self):
105105
"""The HTTP content, parsed into a json dictionary"""
106-
import ujson
107-
return ujson.loads(self.content)
106+
try:
107+
import json as json_module
108+
except ImportError:
109+
import ujson as json_module
110+
return json_module.loads(self.content)
108111

109112
def iter_content(self, chunk_size=1, decode_unicode=False):
110113
"""An iterator that will stream data by only reading 'chunk_size'
@@ -176,8 +179,11 @@ def request(method, url, data=None, json=None, headers=None, stream=False):
176179
sock.write(b"\r\n")
177180
if json is not None:
178181
assert data is None
179-
import ujson
180-
data = ujson.dumps(json)
182+
try:
183+
import json as json_module
184+
except ImportError:
185+
import ujson as json_module
186+
data = json_module.dumps(json)
181187
sock.write(b"Content-Type: application/json\r\n")
182188
if data:
183189
sock.write(b"Content-Length: %d\r\n" % len(data))

0 commit comments

Comments
 (0)