summaryrefslogtreecommitdiff
path: root/cherrypy/_json.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2018-09-04 11:47:59 -0400
committerJason R. Coombs <jaraco@jaraco.com>2018-09-04 11:55:19 -0400
commit5f8d4358cfc7580bdb22e471dd1e4b03cc3887c5 (patch)
treee7d0fc5b30a2b2f15c219b5313821e838783b9c7 /cherrypy/_json.py
parenta7bb4a1416073bf93ab0217099d063810d630818 (diff)
downloadcherrypy-git-5f8d4358cfc7580bdb22e471dd1e4b03cc3887c5.tar.gz
Move json from _cpcompat to its own module.
Diffstat (limited to 'cherrypy/_json.py')
-rw-r--r--cherrypy/_json.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/cherrypy/_json.py b/cherrypy/_json.py
new file mode 100644
index 00000000..0c2a0f0e
--- /dev/null
+++ b/cherrypy/_json.py
@@ -0,0 +1,25 @@
+"""
+JSON support.
+
+Expose preferred json module as json and provide encode/decode
+convenience functions.
+"""
+
+try:
+ # Prefer simplejson
+ import simplejson as json
+except ImportError:
+ import json
+
+
+__all__ = ['json', 'encode', 'decode']
+
+
+decode = json.JSONDecoder().decode
+_encode = json.JSONEncoder().iterencode
+
+
+def encode(value):
+ """Encode to bytes."""
+ for chunk in _encode(value):
+ yield chunk.encode('utf-8')