(self, topic, payload)
return formatted_data, dict(json_data)
Format json for pretty printing, return string suitable for logging,
        and a dict of the json data
Format json for pretty printing, return string suitable for logging,
        and a dict of the json data
Format json for pretty printing return string suitable for logging and a dict of the json data
def decode_payload(self, topic, payload):
        '''
        Format json for pretty printing, return string suitable for logging,
        and a dict of the json data
        '''
        indent = self.master_indent + 31 #number of spaces to indent json data

        try:
            # if it's json data, decode it (use OrderedDict to preserve keys
            # order), else return as is...
            json_data = json.loads(
                payload.decode("utf-8").replace(":nan", ":NaN").\
                replace(":inf", ":Infinity").replace(":-inf", ":-Infinity"))  #removed object_pairs_hook=OrderedDict
            # if it's not a dictionary, probably just a number
            if not isinstance(json_data, dict):
                return json_data, dict(json_data)
            json_data_string = "\n".join((indent * " ") + i for i in \
                (json.dumps(json_data, indent = 2)).splitlines())

            formatted_data = "Decoded JSON: \n%s" % (json_data_string)

        except ValueError:
            formatted_data = payload

        if self.raw:
            formatted_data = payload

        return formatted_data, dict(json_data)
def decode_payload ( self , topic , payload ) : indent = self . master_indent + 31 #number of spaces to indent json data try : # if it's json data, decode it (use OrderedDict to preserve keys # order), else return as is... json_data = json . loads ( payload . decode ( "utf-8" ) . replace ( ":nan" , ":NaN" ) . replace ( ":inf" , ":Infinity" ) . replace ( ":-inf" , ":-Infinity" ) ) #removed object_pairs_hook=OrderedDict # if it's not a dictionary, probably just a number if not isinstance ( json_data , dict ) : return json_data , dict ( json_data ) json_data_string = "\n" . join ( ( indent * " " ) + i for i in ( json . dumps ( json_data , indent = 2 ) ) . splitlines ( ) ) formatted_data = "Decoded JSON: \n%s" % ( json_data_string ) except ValueError : formatted_data = payload if self . raw : formatted_data = payload return formatted_data , dict ( json_data )