The Hakoniwa
class is a Python class designed to handle JSON data stored in a file. It provides methods to parse JSON, search for specific records, insert new records, and update existing records.
Switch to Master
To use the Hakoniwa
class, follow these steps:
- Import the
Hakoniwa
class into your Python script:
from hakoniwa import Hakoniwa
- Create an instance of the
Hakoniwa
class by providing the filename of the JSON file:
hakoniwa = Hakoniwa("data.json")
- Parse the JSON file using the
parseJSON
method:
hakoniwa.parseJSON("data.json")
- Find records that match specific criteria using the
find
method:
matching_records = hakoniwa.find({"key": "value"})
- Insert a new record using the
insert
method:
hakoniwa.insert({"key": "value"})
- Update existing records that match specific criteria using the
update_insert
method:
hakoniwa.update_insert({"key": "value"}, {"new_key": "new_value"})
Static method that parses a JSON file and returns the parsed data as a list of dictionaries.
Parameters:
file
(str): The path to the JSON file.
Finds records in the parsed JSON data that match the specified criteria.
Parameters:
dict_find
(dict): A dictionary containing key-value pairs to match against the records.
Returns:
- A list of dictionaries representing the matched records.
Inserts a new record into the parsed JSON data.
Parameters:
dict_update
(dict): A dictionary representing the new record to be inserted.
Updates the JSON file with the current data records.
Updates existing records that match the specified criteria with the new values provided.
Parameters:
dict_find
(dict): A dictionary containing key-value pairs to match against the records.dict_insert
(dict): A dictionary representing the new values to be inserted into the matching records.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.
- Muneeb Ahmed - Creator
- PyMongo - Inspiration or code snippets
Make sure to replace "data.json"
with the actual filename of your JSON data file.
Click to Reveal Easter Egg
Hakoniwa means Box-Garden it is known as pocket dimension for storage