Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not if you're not willing to lose some speed. If being somewhat slower is OK, you have to consider that using plain <code>json.loads</code> and recursively converting to <code>str</code> is probably cheaper and maybe faster. </p> <p>With all that said, if you do want a <code>loads</code> that returns strings badly enough <strike>to accept going through extending code that wasn't meant to, here's one possible result (mostly extending through copy-n-paste)</strike> this was asinine, thanks Lennart for making me see the light (i.e., you just need to extend JSONDecoder and a couple of tricks):</p> <pre><code>import json from json import decoder, scanner from json.scanner import make_scanner from _json import scanstring as c_scanstring _CONSTANTS = json.decoder._CONSTANTS py_make_scanner = scanner.py_make_scanner # Convert from unicode to str def str_scanstring(*args, **kwargs): result = c_scanstring(*args, **kwargs) return str(result[0]), result[1] # Little dirty trick here json.decoder.scanstring = str_scanstring class StrJSONDecoder(decoder.JSONDecoder): def __init__(self, encoding=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None): self.encoding = encoding self.object_hook = object_hook self.object_pairs_hook = object_pairs_hook self.parse_float = parse_float or float self.parse_int = parse_int or int self.parse_constant = parse_constant or _CONSTANTS.__getitem__ self.strict = strict self.parse_object = decoder.JSONObject self.parse_array = decoder.JSONArray self.parse_string = str_scanstring self.scan_once = py_make_scanner(self) # And another little dirty trick there _default_decoder = StrJSONDecoder(encoding=None, object_hook=None, object_pairs_hook=None) json._default_decoder = _default_decoder j = {1:'2', 1.1:[1,2,3], u'test': {12:12, 13:'o'}} print json.loads(json.dumps(j)) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload