def jsonDumps(data, objName="", schema=None): """ Serialize data with JSON, optionally checking the schema @param data: @param objName: @param schema: @return: """ if schema == None: msg = "No schema given for JSON serialization of "+objName Utils.log(msg, err=True) raise Exception(msg) # Make sure we fail the request else: Schema.validate(schema, data, objName=objName) return json.dumps(data)
def jsonDumps(data, objName="", schema=None): """ Serialize data with JSON, optionally checking the schema @param data: @param objName: @param schema: @return: """ if schema == None: msg = "No schema given for JSON serialization of " + objName Utils.log(msg, err=True) raise Exception(msg) # Make sure we fail the request else: Schema.validate(schema, data, objName=objName) return json.dumps(data)
def jsonLoads(dataStr, objName="", schema=None): """ Deserialize data with JSON, optionally checking the schema @param dataStr: @param objName: @param schema: @return: """ data = json.loads(dataStr) if schema == None: msg = 'No schema given for JSON deserialization of '+objName Utils.log(msg, err=True) raise Exception(msg) # Make sure we fail the request else: Schema.validate(schema, data, objName=objName) return data
def jsonLoads(dataStr, objName="", schema=None): """ Deserialize data with JSON, optionally checking the schema @param dataStr: @param objName: @param schema: @return: """ data = json.loads(dataStr) if schema == None: msg = 'No schema given for JSON deserialization of ' + objName Utils.log(msg, err=True) raise Exception(msg) # Make sure we fail the request else: Schema.validate(schema, data, objName=objName) return data