JSON Validator Converter
JSON Validator Converter Reference#
json_to_dataclass(json_data)
#
Converts a validated JSON object into a SimulationConfig dataclass.
Parameters:#
json_data : dict The validated JSON data representing the simulation configuration.
Returns:#
SimulationConfig
A SimulationConfig object populated with data from the JSON input.
Raises:#
ConfigConversionError If required keys are missing or if there is a type mismatch during conversion.
Source code in SMS_BP/json_validator_converter.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
load_validate_and_convert(file_path)
#
Loads, validates, and converts a simulation configuration file to a SimulationConfig dataclass.
This function reads the JSON configuration file, validates its structure against the schema,
and then converts it to a SimulationConfig dataclass.
Parameters:#
file_path : str Path to the JSON file containing the simulation configuration.
Returns:#
SimulationConfig
A SimulationConfig object populated with the data from the file.
Raises:#
ConfigValidationError If the JSON file is invalid or cannot be loaded. ConfigConversionError If an error occurs during the conversion to the dataclass.
Source code in SMS_BP/json_validator_converter.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
validate_and_convert(loaded_json)
#
Validates and converts an in-memory JSON object to a SimulationConfig dataclass.
This function is useful when the JSON data is already loaded into memory, bypassing the need to read from a file.
Parameters:#
loaded_json : dict The JSON data to validate and convert.
Returns:#
SimulationConfig
A SimulationConfig object populated with data from the JSON input.
Raises:#
ConfigValidationError If the JSON data does not comply with the schema. ConfigConversionError If there is a type mismatch or a key is missing during conversion.
Source code in SMS_BP/json_validator_converter.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
validate_json(json_data)
#
Validates a JSON object against the defined simulation schema.
Parameters:#
json_data : dict The JSON data to be validated.
Returns:#
bool
Returns True if the JSON data is valid.
Raises:#
ConfigValidationError If the JSON data does not comply with the schema.
Source code in SMS_BP/json_validator_converter.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |