All Samples(2357) | Call(2199) | Derive(0) | Import(158)
Serialize ``obj`` to a JSON formatted ``str``.
If ``skipkeys`` is false then ``dict`` keys that are not basic types
(``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
will be skipped instead of raising a ``TypeError``.
If ``ensure_ascii`` is false, then the return value will be a
``unicode`` instance subject to normal Python ``str`` to ``unicode``
coercion rules instead of being escaped to an ASCII ``str``.
If ``check_circular`` is false, then the circular reference check
for container types will be skipped and a circular reference will
result in an ``OverflowError`` (or worse).
If ``allow_nan`` is false, then it will be a ``ValueError`` to
serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in
strict compliance of the JSON specification, instead of using the
JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
If ``indent`` is a string, then JSON array elements and object members
will be pretty-printed with a newline followed by that string repeated
for each level of nesting. ``None`` (the default) selects the most compact
representation without any newlines. For backwards compatibility with
versions of simplejson earlier than 2.1.0, an integer is also accepted
and is converted to a string with that many spaces.
If ``separators`` is an ``(item_separator, dict_separator)`` tuple
then it will be used instead of the default ``(', ', ': ')`` separators.
``(',', ':')`` is the most compact JSON representation.
``encoding`` is the character encoding for str instances, default is UTF-8.
``default(obj)`` is a function that should return a serializable version
of obj or raise TypeError. The default simply raises TypeError.
If *use_decimal* is true (default: ``False``) then decimal.Decimal
will be natively serialized to JSON with full precision.
To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
``.default()`` method to serialize additional types), specify it with
the ``cls`` kwarg.
def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
allow_nan=True, cls=None, indent=None, separators=None,
encoding='utf-8', default=None, use_decimal=False, **kw):
"""Serialize ``obj`` to a JSON formatted ``str``.
If ``skipkeys`` is false then ``dict`` keys that are not basic types
(``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
will be skipped instead of raising a ``TypeError``.
If ``ensure_ascii`` is false, then the return value will be a
``unicode`` instance subject to normal Python ``str`` to ``unicode``
coercion rules instead of being escaped to an ASCII ``str``.
If ``check_circular`` is false, then the circular reference check
for container types will be skipped and a circular reference will
result in an ``OverflowError`` (or worse).
If ``allow_nan`` is false, then it will be a ``ValueError`` to
serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in
strict compliance of the JSON specification, instead of using the
JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
If ``indent`` is a string, then JSON array elements and object members
will be pretty-printed with a newline followed by that string repeated
for each level of nesting. ``None`` (the default) selects the most compact
representation without any newlines. For backwards compatibility with
versions of simplejson earlier than 2.1.0, an integer is also accepted
and is converted to a string with that many spaces.
If ``separators`` is an ``(item_separator, dict_separator)`` tuple
then it will be used instead of the default ``(', ', ': ')`` separators.
``(',', ':')`` is the most compact JSON representation.
``encoding`` is the character encoding for str instances, default is UTF-8.
``default(obj)`` is a function that should return a serializable version
of obj or raise TypeError. The default simply raises TypeError.
If *use_decimal* is true (default: ``False``) then decimal.Decimal
will be natively serialized to JSON with full precision.
To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
``.default()`` method to serialize additional types), specify it with
the ``cls`` kwarg.
"""
# cached encoder
if (not skipkeys and ensure_ascii and
check_circular and allow_nan and
cls is None and indent is None and separators is None and
encoding == 'utf-8' and default is None and not use_decimal
and not kw):
return _default_encoder.encode(obj)
if cls is None:
cls = JSONEncoder
return cls(
skipkeys=skipkeys, ensure_ascii=ensure_ascii,
check_circular=check_circular, allow_nan=allow_nan, indent=indent,
separators=separators, encoding=encoding, default=default,
use_decimal=use_decimal, **kw).encode(obj)
]""")
d1 = simplejson.dumps(h)
d2 = simplejson.dumps(h, indent=2, sort_keys=True, separators=(' ,', ' : '))
h1 = simplejson.loads(d1)
src/p/y/PyAMF-HEAD/doc/tutorials/examples/actionscript/google_appengine/simplejson/tests/test_indent.py PyAMF(Download)
]""")
d1 = simplejson.dumps(h)
d2 = simplejson.dumps(h, indent=2, sort_keys=True, separators=(',', ': '))
h1 = simplejson.loads(d1)
src/p/y/PyAMF-HEAD/doc/tutorials/examples/actionscript/google_appengine/simplejson/tests/test_unicode.py PyAMF(Download)
def test_encoding2():
u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
s = u.encode('utf-8')
ju = S.dumps(u, encoding='utf-8')
js = S.dumps(s, encoding='utf-8')
assert ju == js
def test_big_unicode_encode():
u = u'\U0001d120'
assert S.dumps(u) == '"\\ud834\\udd20"'
assert S.dumps(u, ensure_ascii=False) == '"\\ud834\\udd20"'
src/l/a/lamson-1.0/examples/librelist/app/model/archive.py lamson(Download)
def to_json(base):
return json.dumps(json_build(base), sort_keys=True, indent=4)
src/p/y/PyAMF-HEAD/doc/tutorials/examples/actionscript/google_appengine/simplejson/tests/test_pass1.py PyAMF(Download)
def test_parse():
# test in/out equivalence and parsing
import simplejson
res = simplejson.loads(JSON)
out = simplejson.dumps(res)
assert res == simplejson.loads(out)
try:
simplejson.dumps(res, allow_nan=False)
src/p/y/PyAMF-HEAD/doc/tutorials/examples/actionscript/google_appengine/simplejson/tests/test_default.py PyAMF(Download)
def test_default():
assert simplejson.dumps(type, default=repr) == simplejson.dumps(repr(type))
src/f/r/freebase-1.0.6/examples/freebase-images-appengine/freebase/fcl/commands.py freebase(Download)
# results could be streamed with a little more work
results = fb.mss.mqlreaditer(q)
print simplejson.dumps(list(results), indent=2)
def cmd_open(fb, id):
"""open a web browser on the given id. works on OSX only for now.
for link in linksfrom:
# fb.trow(link.master_property.id, ...)
print simplejson.dumps(link, indent=2)
for link in valuesfrom:
# fb.trow(link.master_property.id, ...)
print simplejson.dumps(link, indent=2)
src/p/y/PyMT-0.5.1/examples/apps/mtwitter/twitter.py PyMT(Download)
def AsJsonString(self):
'''A JSON string representation of this twitter.Status instance.
Returns:
A JSON string representation of this twitter.Status instance
'''
return simplejson.dumps(self.AsDict(), sort_keys=True)
def AsJsonString(self):
'''A JSON string representation of this twitter.User instance.
Returns:
A JSON string representation of this twitter.User instance
'''
return simplejson.dumps(self.AsDict(), sort_keys=True)
def AsJsonString(self):
'''A JSON string representation of this twitter.DirectMessage instance.
Returns:
A JSON string representation of this twitter.DirectMessage instance
'''
return simplejson.dumps(self.AsDict(), sort_keys=True)
src/n/o/notmm-0.4.1/examples/lib/satchmo_utils/json.py notmm(Download)
ret = _any(data)
return json.dumps(ret, cls=DateTimeAwareJSONEncoder)
src/p/y/python-yammer-oauth-HEAD/example.py python-yammer-oauth(Download)
include_replies=include_replies)
yammer.close()
print "Result:"
print simplejson.dumps(r, indent=4)
except YammerError, m:
print "*** Error: %s" % m.message
quit()
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next