JSONManipulator.core package¶
Submodules¶
JSONManipulator.core.AddKey module¶
The module with AddKey class
-
class
JSONManipulator.core.AddKey.AddKey(full_path)¶ Bases:
objectA class to add a new key to each object in the JSON file.
- Args:
full_path (str): the full path to the JSON file.- Raises:
FileNotFoundError: if the JSON file is not found byfull_path.IsADirectoryError: iffull_pathis to a directory, not to the JSON file.
-
add_key() → None¶ Add a key to each object in the JSON file, optionally with a description, with a default value.
JSONManipulator.core.AddObject module¶
The module with AddObject class
JSONManipulator.core.ChangeAllValues module¶
The module with ChangeAllValues class
-
class
JSONManipulator.core.ChangeAllValues.ChangeAllValues(full_path, value='')¶ Bases:
JSONManipulator.core.ChangeValue.ChangeValueA class to change values of all objects in the JSON file.
- Args:
value (str): a redundant parameter, exists as mandatory in the parent class.full_path (str): the full path to the JSON file.- Raises:
FileNotFoundError: if the JSON file is not found byfull_path.IsADirectoryError: iffull_pathis to a directory, not to the JSON file.
-
change_all_values() → None¶ Change the values of all objects in the JSON file.
JSONManipulator.core.ChangeValue module¶
The module with ChangeValue class
-
class
JSONManipulator.core.ChangeValue.ChangeValue(value, full_path, levenshtein=1.0, key=None, desc=None)¶ Bases:
JSONManipulator.core.GetInformation.GetInformationA child class of
GetInformationto change values of found dictionary(-ies) simultaneously.- Args:
key (str): to find the object by the key in the JSON file.desc (str): to find the object by the description.full_path (str): the full path to the JSON file.value (str): the value ofkey/descwhich will be used to find the object(s).levenshtein (float): the similarity of the elicited objects to the input. By default, seeks 100% similarity.- Raises:
exceptions.NoKeyAndDesc: if neitherkeynordescis entered.FileNotFoundError: if the JSON file is not found byfull_path.IsADirectoryError: iffull_pathis to a directory, not to the JSON file.
-
change_one_object(start_dictionary) → None¶ Change user-chosen values from the object -
start_dictionary.
-
change_several_objects(start_list_dictionaries) → None¶ Change several objects from
start_list_dictionariessimultaneously.
-
change_value() → None¶ Inheritably call
get_information(), then call additional in-class functions to change values of the object(s).
-
desc¶
-
static
format_several_objects(user_option, dictionary_container) → List[Dict[KT, VT]]¶ Process
user_optionand take user-chosen objects fromdictionary_container.- Args:
user_option (str): numbers of chosen dictionaries, for example, “2-4,10”.dictionary_container (list): the list to take dictionaries from.- Returns:
List[Dict]: the list of dictionaries which values it is necessary to change.
-
full_path¶
-
static
if_clauses(type_value, changed_dictionary, key_in_initial_dict, desc, new_value) → None¶ Set new values to the objects in the JSON file.
-
key¶
-
levenshtein¶
-
value¶
JSONManipulator.core.DeleteObject module¶
The module with DeleteObject class
-
class
JSONManipulator.core.DeleteObject.DeleteObject(value, full_path, levenshtein=1.0, key=None, desc=None)¶ Bases:
JSONManipulator.core.ChangeValue.ChangeValueA class to delete found objects.
- Args:
key (str): to find the object by the key in the JSON file.desc (str): to find the object by the description.full_path (str): the full path to the JSON file.value (str): the value ofkey/descwhich will be used to find the object(s).levenshtein (float): the similarity of the elicited objects to the input. By default, seeks 100% similarity.- Raises:
exceptions.NoKeyAndDesc: if neitherkeynordescis entered.FileNotFoundError: if the JSON file is not found byfull_path.IsADirectoryError: iffull_pathis to a directory, not to the JSON file.
-
delete_object() → None¶ Take the list of objects, after a user chose ones to delete, call
execute_delete()function.
-
desc¶
-
execute_delete(dict_container) → None¶ Delete redundant objects.
-
full_path¶
-
key¶
-
levenshtein¶
-
value¶
JSONManipulator.core.GetInformation module¶
The module with GetInformation class
-
class
JSONManipulator.core.GetInformation.GetInformation(value, full_path, levenshtein=1.0, key=None, desc=None)¶ Bases:
objectThe base class to retrieve the information about desired object(s).
- Args:
key (str): to find the object by the key in the JSON file.desc (str): to find the object by the description.full_path (str): the full path to the JSON file.value (str): the value ofkey/descwhich will be used to find the object(s).levenshtein (float): the similarity of the elicited objects to the input. By default, seeks 100% similarity.- Raises:
exceptions.NoKeyAndDesc: if neitherkeynordescis entered.FileNotFoundError: if the JSON file is not found byfull_path.IsADirectoryError: iffull_pathis to a directory, not to the JSON file.
-
static
cap_sentence(string) → bool¶ Check if
stringlooks like a person’s first, middle or/and last names.- Returns:
True: if the entered data is about a person.False: else.
-
desc¶
-
full_path¶
-
get_information() → List[Dict[KT, VT]]¶ Process the user’s parameters and the JSON file’s values, then call additional in-class functions to analyse data and output objects, accordingly.
- Returns:
List[Dict]: ifGetInformationis a parent class - forlist of dictionariesmanipulations.None: else.
-
key¶
-
levenshtein¶
-
levenshtein_calc(dictionary_value, dictionary) → None¶ Compare processed
object.valueanddictionary_value, and if the similarity is higher thanobject.levenshtein- append to the list for the further output.
-
output_dict_container¶
-
output_for_key_and_value() → None¶ Process
object.output_dict_containerfromlevenshtein_calc(), beautify the output of the objects.
-
value¶
JSONManipulator.core.set_up module¶
The module with set_up function
-
JSONManipulator.core.set_up.set_up(full_path) → None¶ Configure the initial JSON file. Add descriptions for the keys in the JSON file for the further more readable retrieval.
- Args:
full_path (str): the path to the desired file.- Raises:
FileNotFoundError: if the JSON file is not found byfull_path.IsADirectoryError: iffull_pathis to a directory, not to the JSON file.exception.NotSupportedJSONFile: if the JSON file is not supported by the package.
Module contents¶
The JSONManipulator’s core module with all the classes and functions.