This project provides a framework for decoding tables from JSON and CSV formats into Python dictionaries.
csv– for handling CSV filesjson– for parsing JSON datacollections.defaultdict– for structured storageio.StringIO– for handling in-memory CSV streamspathlib.Path– for file operationspprint.pprint– for pretty-printing output
- Maintains a registry of available decoders.
- Defines a factory method (
create()) to instantiate decoders dynamically. - Requires subclasses to implement a
decode(text)method.
- Parses JSON arrays of dictionaries into a column-based format.
- Reads CSV files and converts them into a column-based dictionary.
- Detects file type based on extension.
- Loads and decodes the table using the corresponding decoder.
- Prints available decoders.
- Loads a sample JSON table and prints the result.
Run the script:
python table_encoders.pyThis will print the available decoders (['json', 'csv']), load and print the content of table.json in dictionary format:
['json', 'csv']
{'temperature': [2, 8, 12], 'time': [7, 10, 15]}Piotr Lipiński
Contributions, issues, and feedback are welcome! 🤝