Python jsonpickle.set_encoder_options() Examples

The following are 5 code examples of jsonpickle.set_encoder_options(). 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 also want to check out all available functions/classes of the module jsonpickle , or try the search function .
Example #1
Source File: __init__.py    From pros-cli2 with Mozilla Public License 2.0 5 votes vote down vote up
def save(self, file=None):
        if file is None:
            file = self.save_file
        if isinstance(click.get_current_context().obj, proscli.utils.State) and click.get_current_context().obj.debug:
            proscli.utils.debug('Pretty Formatting {} File'.format(self.__class__.__name__))
            jsonpickle.set_encoder_options('json', sort_keys=True, indent=4)
        else:
            jsonpickle.set_encoder_options('json', sort_keys=True)
        if os.path.dirname(file):
            os.makedirs(os.path.dirname(file), exist_ok=True)
        with open(file, 'w') as f:
            f.write(jsonpickle.encode(self)) 
Example #2
Source File: submission.py    From Liked-Saved-Image-Downloader with MIT License 5 votes vote down vote up
def getJson(self):
        jsonpickle.set_preferred_backend('json')
        jsonpickle.set_encoder_options('json', ensure_ascii=False, indent=4, separators=(',', ': '))
        return jsonpickle.encode(self) 
Example #3
Source File: sdp.py    From lethean-vpn with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def getJson(self):
        self.load(None)
        jsonpickle.set_encoder_options('json', sort_keys=True, indent=3)
        json = jsonpickle.encode(self.data, unpicklable=False)
        log.L.debug('Encoded SDP JSON: %s' % json)
        return json 
Example #4
Source File: sdp.py    From lethean-vpn with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def getJson(self):
        jsonpickle.set_encoder_options('json', sort_keys=True, indent=3)
        json = jsonpickle.encode(self.data, unpicklable=False)
        log.L.info('Encoded SDP Service JSON: %s' % json)
        return json 
Example #5
Source File: util.py    From vakt with Apache License 2.0 5 votes vote down vote up
def to_json(self, sort=False):
        """
        Get JSON representation of an object
        """
        jsonpickle.set_encoder_options('json', sort_keys=sort)
        return jsonpickle.encode(self._data())