├── LICENSE.md ├── README.md ├── json2yaml.py └── requirements.txt /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Harishkumar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🔁 JSON2YAML 2 | **JSON2YAML** is a Python-based utility that simplifies the process of converting CVE (Common Vulnerabilities and Exposures) data from JSON format into well-structured YAML files. This tool allows security analysts and developers to easily manage, analyze, and integrate CVE data into their vulnerability management systems. 3 | 4 | With **JSON2YAML**, you can seamlessly convert detailed CVE records into a readable YAML format, making it easier to work with tools that require YAML files or to maintain your own vulnerability databases. 5 | 6 | ## 📌 Features: 7 | - **Automatic CVE Parsing:** Automatically extracts the CVE number from the provided JSON data and uses it as the filename for the YAML output. 8 | - **Structured Output:** Converts raw CVE JSON data into a neatly formatted YAML file, retaining important information such as descriptions, CVSS scores, references, and affected software. 9 | - **Error Handling:** Provides error messages when the required CVE data is missing or improperly formatted. 10 | - **Easy-to-Use:** A simple, command-line based tool that converts individual CVEs or batches of CVE data quickly and efficiently. 11 | # 12 | ## Example Input: 13 | **Provide a JSON file with CVE details such as ID, description, CVSS score, references, and affected products.** 14 | ![Screenshot 2024-12-04 082124](https://github.com/user-attachments/assets/18e24f94-0912-4d3f-b9bc-1e9706c39b98) 15 | 16 | ## JSON2YAML conversion 17 | ![Screenshot 2024-12-04 082034](https://github.com/user-attachments/assets/ac9575aa-8cbd-4422-abaa-96b84b0a1e27) 18 | 19 | ## Example Output: 20 | **A neatly formatted YAML file with structured CVE information.** 21 | ![Screenshot 2024-12-04 082205](https://github.com/user-attachments/assets/edd6b840-7cd7-4c0c-9fa2-499bf5e0efb5) 22 | 23 | # 24 | ## ⚙️ Installation 25 | ## Clone the Repository 26 | ```bash 27 | git clone https://github.com/whitehatboy005/JSON2YAML-CVE 28 | cd JSON2YAML-CVE 29 | ``` 30 | ## Install Dependencies 31 | ```bash 32 | pip install -r requirements.txt 33 | ``` 34 | ## Usage: 35 | **To convert a CVE JSON file to YAML, run the script:** 36 | ```bash 37 | python json2yaml.py 38 | ``` 39 | - **Input the path to your JSON file when prompted.** 40 | - **The script will automatically generate a YAML file named after the CVE ID.** 41 | 42 | ## 👨‍💻 Contribution: 43 | **Contributions are welcome! If you have any suggestions for improvements or bug fixes, feel free to submit a pull request.** 44 | 45 | ## 📝 License: 46 | This project is licensed under the terms of the [MIT license](LICENSE.md). 47 | -------------------------------------------------------------------------------- /json2yaml.py: -------------------------------------------------------------------------------- 1 | import json 2 | import yaml 3 | import os 4 | 5 | def convert_json_to_yaml(json_file): 6 | try: 7 | # Read the JSON data 8 | with open(json_file, 'r') as file: 9 | data = json.load(file) 10 | 11 | # Access CVE number from the nested structure 12 | cve_number = next(iter(data.get("data", {}).get("documents", {}).keys()), None) 13 | if not cve_number: 14 | raise ValueError("CVE number not found in JSON data.") 15 | 16 | # Create YAML file name based on the CVE number 17 | yaml_file = f"{cve_number}.yaml" 18 | 19 | # Convert JSON to YAML and write it to a file 20 | with open(yaml_file, 'w') as file: 21 | yaml.dump(data, file, default_flow_style=False, sort_keys=False) 22 | 23 | print(f"Conversion complete! YAML file saved as {yaml_file}") 24 | 25 | except FileNotFoundError: 26 | print(f"Error: File '{json_file}' not found. Please check the file path.") 27 | except json.JSONDecodeError: 28 | print(f"Error: Failed to parse JSON. Please check if '{json_file}' contains valid JSON.") 29 | except Exception as e: 30 | print(f"An unexpected error occurred: {e}") 31 | 32 | # Provide file paths dynamically 33 | json_file = input('Please provide the JSON input file path: ').strip() 34 | 35 | convert_json_to_yaml(json_file) 36 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | PyYAML==6.0.2 2 | --------------------------------------------------------------------------------