Currently, there is a JSON parsing class (include/open_atmos/mechanism_configuration/json_parser.hpp; src/json_parser.cpp) that is used to read mechanism configuration files, which uses the nlohmann::json library. There is also a stubbed-out version of a equivalent YAML parser that has yet to be implemented (include/open_atmos/mechanism_configuration/yaml_parser.hpp; src/yaml_parser.cpp).
As we've learned, yaml-cpp can parse json as well as yaml. Replace the existing json and to-be-implemented yaml parsers with a single json/yaml parser that reads both types of files.
Acceptance criteria
- nlohmann::json is removed
- all parsing is done with yaml-cpp
- Existing tests that parse json still work
- New tests are added that parse corresponding yaml examples
Ideas
- Something similar was done in micm, this PR could act as a guide
- Instead of separating the unit tests into yaml and json folders, put all tests for both config types into a single test file
- Ensure all of these are taken care of
- use this (chatgpt generated) python scrip to convert any existing json samples to yaml
import json
import yaml
def json_to_yaml(json_file_path, yaml_file_path):
"""
Reads a JSON file and exports its contents to a YAML file.
:param json_file_path: Path to the JSON file to read.
:param yaml_file_path: Path to the YAML file to write.
"""
try:
# Open and read the JSON file
with open(json_file_path, 'r') as json_file:
data = json.load(json_file)
# Write the data to a YAML file
with open(yaml_file_path, 'w') as yaml_file:
yaml.dump(data, yaml_file, default_flow_style=False)
print(f"Successfully converted {json_file_path} to {yaml_file_path}")
except FileNotFoundError:
print(f"Error: The file {json_file_path} does not exist.")
except json.JSONDecodeError:
print(f"Error: Failed to decode JSON from the file {json_file_path}.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
# Example usage
if __name__ == "__main__":
# Replace with your file paths
input_json_file = "input.json"
output_yaml_file = "output.yaml"
json_to_yaml(input_json_file, output_yaml_file)
Currently, there is a JSON parsing class (
include/open_atmos/mechanism_configuration/json_parser.hpp;src/json_parser.cpp) that is used to read mechanism configuration files, which uses thenlohmann::jsonlibrary. There is also a stubbed-out version of a equivalent YAML parser that has yet to be implemented (include/open_atmos/mechanism_configuration/yaml_parser.hpp;src/yaml_parser.cpp).As we've learned, yaml-cpp can parse json as well as yaml. Replace the existing json and to-be-implemented yaml parsers with a single json/yaml parser that reads both types of files.
Acceptance criteria
Ideas