Python ujson.encode() Examples
The following are 7
code examples of ujson.encode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ujson
, or try the search function
.
Example #1
Source File: external_modules.py From script-languages with MIT License | 6 votes |
def setUp(self): self.query('DROP SCHEMA t1 CASCADE', ignore_errors=True) self.query('CREATE SCHEMA t1') self.query(dedent('''\ CREATE python3 SCALAR SCRIPT ujson_decode(json VARCHAR(10000)) RETURNS VARCHAR(10000) AS import json import ujson def run(ctx): return json.dumps(ujson.decode(ctx.json)) ''')) self.query(dedent('''\ CREATE python3 SCALAR SCRIPT ujson_encode(json VARCHAR(10000)) RETURNS VARCHAR(10000) AS import json import ujson def run(ctx): return ujson.encode(json.loads(ctx.json)) '''))
Example #2
Source File: json_serializer.py From indy-plenum with Apache License 2.0 | 5 votes |
def encode(o): if isinstance(o, (bytes, bytearray)): return '"{}"'.format(base64.b64encode(o).decode("utf-8")) else: return uencode(o, sort_keys=True)
Example #3
Source File: general_utils.py From policy_diffusion with MIT License | 5 votes |
def next(self): return self.reader.next().encode("utf-8")
Example #4
Source File: general_utils.py From policy_diffusion with MIT License | 5 votes |
def writerow(self, row): '''writerow(unicode) -> None This function takes a Unicode string and encodes it to the output. ''' self.writer.writerow([s.encode("utf-8") for s in row]) data = self.queue.getvalue() data = data.decode("utf-8") data = self.encoder.encode(data) self.stream.write(data) self.queue.truncate(0)
Example #5
Source File: general_utils.py From policy_diffusion with MIT License | 5 votes |
def bill_source_to_json(url,source,date): jsonObj = {} jsonObj['url'] = url jsonObj['date'] = date jsonObj['source'] = base64.b64encode(source) return ujson.encode(jsonObj) #creates a json object for bill sources (not encoded)
Example #6
Source File: general_utils.py From policy_diffusion with MIT License | 5 votes |
def bill_source_to_json_not_encoded(url,source,date): jsonObj = {} jsonObj['url'] = url jsonObj['date'] = date jsonObj['source'] = source return ujson.encode(jsonObj) #wrapper for urllib2.urlopen that catches URLERROR and socket error
Example #7
Source File: server.py From palladium with Apache License 2.0 | 5 votes |
def make_ujson_response(obj, status_code=200): """Encodes the given *obj* to json and wraps it in a response. :return: A Flask response. """ json_encoded = ujson.encode(obj, ensure_ascii=False) resp = make_response(json_encoded) resp.mimetype = 'application/json' resp.content_type = 'application/json; charset=utf-8' resp.status_code = status_code return resp