-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
File ModuleRelated to the "File" module inside FileSystemProRelated to the "File" module inside FileSystemProWrapper ModuleRelated to the "Wrapper" module inside FileSystemProRelated to the "Wrapper" module inside FileSystemPro
Description
Develop a Python function that takes a list of item names and their corresponding values as parameters, iterates over the names, and creates a JSON file with the resulting structure. The function should associate each name with its respective value, producing a well-formatted JSON file.
Task Details:
- Objective: Create a function that:
- Takes two parameters:
names: a list of strings representing the item names.values: a list of values (can be any JSON-compatible type, such as strings, numbers, booleans, etc.).
- Iterates over the list of names and associates each name with its corresponding value.
- Generates a JSON file with the resulting structure.
- Takes two parameters:
- Requirements:
- The function must validate that the
namesandvalueslists have the same length. If not, it should raise an exception with a clear message. - The generated JSON file must be saved to a specified path (either as an additional parameter or a default path).
- The JSON file should be well-formatted (e.g., using
indent=4with thejsonlibrary). - Ensure that the value types are JSON-compatible.
- The function must validate that the
- Example Usage:
Expected Output (output.json):
names = ["item1", "item2", "item3"] values = [10, "text", True] create_json(names, values, "output.json")
{ "item1": 10, "item2": "text", "item3": true } - Acceptance Criteria:
- The function must correctly create the JSON file based on the provided parameters.
- It should handle errors such as lists of different lengths or invalid data types.
- The generated JSON file must be valid and readable.
- Unit tests must be implemented to verify:
- Correct creation of the JSON file.
- Error handling for lists of different lengths.
- Validation of JSON-compatible data types.
- Additional Notes:
- Use Python's standard
jsonlibrary for JSON file manipulation. - Consider adding an optional parameter to specify the output file name/path.
- Document the function with a docstring explaining parameters, return value, and possible exceptions.
- Use Python's standard
Metadata
Metadata
Assignees
Labels
File ModuleRelated to the "File" module inside FileSystemProRelated to the "File" module inside FileSystemProWrapper ModuleRelated to the "Wrapper" module inside FileSystemProRelated to the "Wrapper" module inside FileSystemPro