Python json.encoder() Examples
The following are 30 code examples for showing how to use json.encoder(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
json
, or try the search function
.
Example 1
Project: jx-sqlite Author: mozilla File: encoder.py License: Mozilla Public License 2.0 | 6 votes |
def encode(self, value, pretty=False): if pretty: return pretty_json(value) try: with Timer("scrub", too_long=0.1): scrubbed = scrub(value) param = {"size": 0} with Timer("encode {{size}} characters", param=param, too_long=0.1): output = text(self.encoder(scrubbed)) param["size"] = len(output) return output except Exception as e: from mo_logs.exceptions import Except from mo_logs import Log e = Except.wrap(e) Log.warning("problem serializing {{type}}", type=text(repr(value)), cause=e) raise e
Example 2
Project: pyquarkchain Author: QuarkChain File: slogging.py License: MIT License | 5 votes |
def format_message(self, msg, kwargs, highlight, level): if getattr(self, 'log_json', False): message = dict() message['event'] = '{}.{}'.format( self.name, msg.lower().replace(' ', '_')) message['level'] = logging.getLevelName(level) try: message.update(kwargs) try: msg = json.dumps(message, cls=_LogJSONEncoder) except TypeError: # Invalid value. With our custom encoder this can only happen with non-string # dict keys (see: https://bugs.python.org/issue18820). message = _stringify_dict_keys(message) msg = json.dumps(message, cls=_LogJSONEncoder) except UnicodeDecodeError: message.update({ k: v if is_numeric(v) or isinstance(v, (float, complex)) else repr(v) for k, v in kwargs.items() }) msg = json.dumps(message, cls=_LogJSONEncoder) else: msg = "{}{} {}{}".format( bcolors.WARNING if highlight else "", msg, " ".join("{}={!s}".format(k, v) for k, v in kwargs.items()), bcolors.ENDC if highlight else "" ) return msg
Example 3
Project: ironpython2 Author: IronLanguages File: __init__.py License: Apache License 2.0 | 5 votes |
def test_pyjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, 'json.scanner') self.assertEqual(self.json.decoder.scanstring.__module__, 'json.decoder') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, 'json.encoder')
Example 4
Project: ironpython2 Author: IronLanguages File: __init__.py License: Apache License 2.0 | 5 votes |
def test_cjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, '_json') self.assertEqual(self.json.decoder.scanstring.__module__, '_json') self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, '_json')
Example 5
Project: ironpython2 Author: IronLanguages File: __init__.py License: Apache License 2.0 | 5 votes |
def additional_tests(): suite = unittest.TestSuite() for mod in (json, json.encoder, json.decoder): suite.addTest(doctest.DocTestSuite(mod)) suite.addTest(TestPyTest('test_pyjson')) suite.addTest(TestCTest('test_cjson')) return suite
Example 6
Project: Computable Author: ktraunmueller File: __init__.py License: MIT License | 5 votes |
def additional_tests(): import json import json.encoder import json.decoder suite = unittest.TestSuite() for mod in (json, json.encoder, json.decoder): suite.addTest(doctest.DocTestSuite(mod)) return suite
Example 7
Project: oss-ftp Author: aliyun File: __init__.py License: MIT License | 5 votes |
def test_pyjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, 'json.scanner') self.assertEqual(self.json.decoder.scanstring.__module__, 'json.decoder') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, 'json.encoder')
Example 8
Project: oss-ftp Author: aliyun File: __init__.py License: MIT License | 5 votes |
def test_cjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, '_json') self.assertEqual(self.json.decoder.scanstring.__module__, '_json') self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, '_json')
Example 9
Project: oss-ftp Author: aliyun File: __init__.py License: MIT License | 5 votes |
def additional_tests(): suite = unittest.TestSuite() for mod in (json, json.encoder, json.decoder): suite.addTest(doctest.DocTestSuite(mod)) suite.addTest(TestPyTest('test_pyjson')) suite.addTest(TestCTest('test_cjson')) return suite
Example 10
Project: Fluid-Designer Author: Microvellum File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def test_pyjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, 'json.scanner') self.assertEqual(self.json.decoder.scanstring.__module__, 'json.decoder') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, 'json.encoder')
Example 11
Project: Fluid-Designer Author: Microvellum File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def test_cjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, '_json') self.assertEqual(self.json.decoder.scanstring.__module__, '_json') self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, '_json')
Example 12
Project: Fluid-Designer Author: Microvellum File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def load_tests(loader, _, pattern): suite = unittest.TestSuite() for mod in (json, json.encoder, json.decoder): suite.addTest(doctest.DocTestSuite(mod)) suite.addTest(TestPyTest('test_pyjson')) suite.addTest(TestCTest('test_cjson')) pkg_dir = os.path.dirname(__file__) return support.load_package_tests(pkg_dir, loader, suite, pattern)
Example 13
Project: ironpython3 Author: IronLanguages File: __init__.py License: Apache License 2.0 | 5 votes |
def test_pyjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, 'json.scanner') self.assertEqual(self.json.decoder.scanstring.__module__, 'json.decoder') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, 'json.encoder')
Example 14
Project: ironpython3 Author: IronLanguages File: __init__.py License: Apache License 2.0 | 5 votes |
def test_cjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, '_json') self.assertEqual(self.json.decoder.scanstring.__module__, '_json') self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, '_json')
Example 15
Project: ironpython3 Author: IronLanguages File: __init__.py License: Apache License 2.0 | 5 votes |
def load_tests(loader, _, pattern): suite = unittest.TestSuite() for mod in (json, json.encoder, json.decoder): suite.addTest(doctest.DocTestSuite(mod)) suite.addTest(TestPyTest('test_pyjson')) suite.addTest(TestCTest('test_cjson')) pkg_dir = os.path.dirname(__file__) return support.load_package_tests(pkg_dir, loader, suite, pattern)
Example 16
Project: openwrt Author: drcoms File: __init__.py License: GNU Affero General Public License v3.0 | 5 votes |
def test_pyjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, 'json.scanner') self.assertEqual(self.json.decoder.scanstring.__module__, 'json.decoder') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, 'json.encoder')
Example 17
Project: openwrt Author: drcoms File: __init__.py License: GNU Affero General Public License v3.0 | 5 votes |
def test_cjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, '_json') self.assertEqual(self.json.decoder.scanstring.__module__, '_json') self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, '_json')
Example 18
Project: openwrt Author: drcoms File: __init__.py License: GNU Affero General Public License v3.0 | 5 votes |
def additional_tests(): suite = unittest.TestSuite() for mod in (json, json.encoder, json.decoder): suite.addTest(doctest.DocTestSuite(mod)) suite.addTest(TestPyTest('test_pyjson')) suite.addTest(TestCTest('test_cjson')) return suite
Example 19
Project: jx-sqlite Author: mozilla File: encoder.py License: Mozilla Public License 2.0 | 5 votes |
def __init__(self, sort_keys=True): object.__init__(self) self.encoder = utf8_json_encoder
Example 20
Project: Project-New-Reign---Nemesis-Main Author: ShikyoKira File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def test_pyjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, 'json.scanner') self.assertEqual(self.json.decoder.scanstring.__module__, 'json.decoder') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, 'json.encoder')
Example 21
Project: Project-New-Reign---Nemesis-Main Author: ShikyoKira File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def test_cjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, '_json') self.assertEqual(self.json.decoder.scanstring.__module__, '_json') self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, '_json')
Example 22
Project: Project-New-Reign---Nemesis-Main Author: ShikyoKira File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def load_tests(loader, _, pattern): suite = unittest.TestSuite() for mod in (json, json.encoder, json.decoder): suite.addTest(doctest.DocTestSuite(mod)) suite.addTest(TestPyTest('test_pyjson')) suite.addTest(TestCTest('test_cjson')) pkg_dir = os.path.dirname(__file__) return support.load_package_tests(pkg_dir, loader, suite, pattern)
Example 23
Project: CTFCrackTools-V2 Author: Acmesec File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def test_pyjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, 'json.scanner') self.assertEqual(self.json.decoder.scanstring.__module__, 'json.decoder') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, 'json.encoder')
Example 24
Project: CTFCrackTools-V2 Author: Acmesec File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def test_cjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, '_json') self.assertEqual(self.json.decoder.scanstring.__module__, '_json') self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, '_json')
Example 25
Project: CTFCrackTools-V2 Author: Acmesec File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def additional_tests(): suite = unittest.TestSuite() for mod in (json, json.encoder, json.decoder): suite.addTest(doctest.DocTestSuite(mod)) suite.addTest(TestPyTest('test_pyjson')) suite.addTest(TestCTest('test_cjson')) return suite
Example 26
Project: CTFCrackTools-V2 Author: Acmesec File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def test_pyjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, 'json.scanner') self.assertEqual(self.json.decoder.scanstring.__module__, 'json.decoder') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, 'json.encoder')
Example 27
Project: CTFCrackTools-V2 Author: Acmesec File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def test_cjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, '_json') self.assertEqual(self.json.decoder.scanstring.__module__, '_json') self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, '_json')
Example 28
Project: CTFCrackTools Author: Acmesec File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def test_pyjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, 'json.scanner') self.assertEqual(self.json.decoder.scanstring.__module__, 'json.decoder') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, 'json.encoder')
Example 29
Project: CTFCrackTools Author: Acmesec File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def test_cjson(self): self.assertEqual(self.json.scanner.make_scanner.__module__, '_json') self.assertEqual(self.json.decoder.scanstring.__module__, '_json') self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json') self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__, '_json')
Example 30
Project: CTFCrackTools Author: Acmesec File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def additional_tests(): suite = unittest.TestSuite() for mod in (json, json.encoder, json.decoder): suite.addTest(doctest.DocTestSuite(mod)) suite.addTest(TestPyTest('test_pyjson')) suite.addTest(TestCTest('test_cjson')) return suite