Jump to >

djblets.util.serializers

class DjbletsJSONEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding=’utf-8’, default=None)[source]

Bases: django.core.serializers.json.DjangoJSONEncoder

A JSON encoder that supports lazy strings, datetimes, and some models.

This is a specialization of DjangoJSONEncoder the does the following:

  • Evaluates strings translated with ugettext_lazy() or gettext_lazy() to real strings.
  • Removes the milliseconds and microseconds from datetimes.
  • Serializes Django models with a to_json method via that method.
default(obj)[source]

Encode the object into a JSON-compatible structure.

Parameters:obj (object) – The object to encode.
Returns:A JSON-compatible structure (e.g., a dict, list, py:class:unicode, or bytes object).
Return type:object