Util
asJSONPrettyString
Convert an object to a pretty-printed JSON string.
Util.asJSONPrettyString(obj: Any) -> strParameters
obj: Object to convert.Returns
A pretty-printed JSON string representation of the object.convertToResult
Convert a response to a Result object if possible.
Util.convertToResult(r) -> Result or NoneParameters
r: Response object to convert.Returns
Result object if conversion is successful, otherwise None.asJSONString
Convert an object to a JSON string.
Util.asJSONString(obj: Any) -> strParameters
obj: Object to convert.Returns
JSON string representation of the object.fromJSONString
Convert a JSON string to an object of the specified class.
Util.fromJSONString(json_str: str, cls: Any) -> AnyParameters
json_str: JSON string to convert.
cls: Class of the object to create.Returns
Object created from the JSON stringfromJSONStringAsMap
Convert a JSON string to a dictionary.
Util.fromJSONStringAsMap(json_str: str) -> Dict[str, Any]Parameters
json_str: JSON string to convert.Returns
Dictionary created from the JSON string.saveAsJSONString
Save an object as JSON to a file.
Util.saveAsJSONString(file_path: str, obj: Any) -> NoneParameters
file_path: Path of the file to save.
obj: Object to save as JSON.Returns
None.fromStringToDate
Convert a string to a datetime object.
Util.fromStringToDate(date, format="%Y-%m-%d %H:%M:%S") -> datetimeParameters
date: String representing the date.
format: Format of the date string (default is "%Y-%m-%d %H:%M:%S").Returns
Datetime object.fromDateToString
Convert a datetime object to a string.
Util.fromDateToString(date: datetime, format: str = "%Y-%m-%d %H:%M:%S") -> strParameters
date: Datetime object to convert.
format: Format of the output string (default is "%Y-%m-%d %H:%M:%S").Returns
String representing the datetime.genRandomAlphaNum
Generate a random alphanumeric string of specified length.
Util.genRandomAlphaNum(length: int) -> strParameters
length: Length of the generated string.Returns
Random alphanumeric string.mapByDisplayNames
Map objects by display names.
Util.mapByDisplayNames(input_map: Dict[str, Any], names: List[str], displayNames: List[str]) -> Dict[str, Any]Parameters
input_map: Input map to process.
names: List of names.
displayNames: List of display names.Returns
Mapped dictionary.listByDisplayNames
List objects by display names.
Util.listByDisplayNames(input_list: List[Dict[str, Any]], names: List[str], displayNames: List[str]) -> List[Dict[str, Any]]Parameters
input_list: Input list to process.
names: List of names.
displayNames: List of display names.Returns
List of dictionaries.deepCopy
Create a deep copy of a dictionary.
Util.deepCopy(input_map: Dict[str, Any]) -> Dict[str, Any]Parameters
input_map: Input dictionary to copy.Returns
Deep copy of the dictionary.convertToListOfDict
Convert input object to a list of dictionaries.
Util.convertToListOfDict(input_object) -> List[Dict[str, Any]]Parameters
input_object: Input object to convert.Returns
List of dictionaries.convertToList
Convert input object to a list.
Util.convertToList(input_object) -> List[Any]Parameters
input_object: Input object to convert.Returns
List.convertToInt
Convert input object to an integer.
Util.convertToInt(input_object) -> intParameters
input_object: Input object to convert.Returns
Integer.convertToDict
Convert input object to a dictionary.
Util.convertToDict(input_object) -> Dict[str, Any]Parameters
input_object: Input object to convert.Returns
Dictionary.convertToBool
Convert input object to a boolean.
Util.convertToBool(input_object) -> boolParameters
input_object: Input object to convert.Returns
Boolean.uidToClassName
Extract class name from UID.
Util.uidToClassName(uid) -> str or NoneParameters
uid: UID string.Returns
Class name extracted from the UID.uidToId
Extract ID from UID.
Util.uidToId(uid) -> intParameters
uid: UID string.Returns
ID extracted from the UID.uidToIdStr
Extract ID as string from UID.
Util.uidToIdStr(uid) -> str or NoneParameters
uid: UID string.Returns
ID as string extracted from the UID.validateJson
Validate JSON string.
Util.validateJson(json_str) -> boolParameters
json_str: JSON string to validate.Returns
True if valid JSON, False otherwise.toPrettyJSONString
Convert JSON string to pretty-printed JSON string.
Util.toPrettyJSONString(json_str) -> strParameters
json_str: JSON string to convert.Returns
Pretty-printed JSON string.getCurrentLanguage
Get the current language.
Util.getCurrentLanguage() -> strParameters
None.Returns
Current language.asUid
Convert class name and ID to UID.
Util.asUid(className, _id=None) -> strParameters
className: Class name.
_id: ID (optional).Returns
UID.addObjectByPath
Add object to dictionary by path.
Util.addObjectByPath(map_, path, value)Parameters
map_: Dictionary to add the object to.
path: Path to the object.
value: Object to add.Returns
None.removeLeadingChars
Remove leading characters from a string.
Util.removeLeadingChars(s, c) -> strParameters
s: Input string.
c: Character to remove.Returns
String with leading characters removed.removeLastCharIfMatches
Remove last character from a string if it matches a specified character.
Util.removeLastCharIfMatches(s, c) -> strParameters
s: Input string.
c: Character to match.Returns
String with last character removed if it matches the specified character.roundDouble
Round a floating-point number to specified decimal places.
Util.roundDouble(value: float, places: int) -> floatParameters
value: Floating-point number to round.
places: Number of decimal places.Returns
Rounded floating-point number.urlEncode
URL-encode a string.
Util.urlEncode(s: str) -> strParameters
s: String to encode.Returns
URL-encoded string.urlDecode
URL-decode a string.
Util.urlDecode(s: str) -> strParameters
s: String to decode.Returns
URL-decoded string.Last updated