'Returns a document in object format for output as JSON.
The stale parameter, when True, accepts stale cached data even after
the document has been modified.'

def get_json_data(self, stale=True):

    curr_json_data = getattr(self, '_json_data', None)
    if (curr_json_data and stale):
        return curr_json_data
    self._json_data = {}
    if self.json:
        try:
            self._json_data = json.loads(self.json)
        except (TypeError, ValueError):
            pass
    json_lmod = self._json_data.get('json_modified', '')
    doc_lmod = self.modified.isoformat()
    if ((not self._json_data) or ((not stale) and (doc_lmod > json_lmod))):
        self._json_data = self.build_json_data()
        self.json = json.dumps(self._json_data)
        if (not settings.MAINTENANCE_MODE):
            Document.objects.filter(pk=self.pk).update(json=self.json)
    return self._json_data
