A tool to convert JSON to model code in various languages
Project description
JsonModeler
JsonModeler is a tool that converts JSON data into model code in multiple programming languages, including C++, C#, Dart, Go, Java, JavaScript, Kotlin, Objective-C, PHP, Python, Swift, and TypeScript.
Project structure
JsonModeler/
├── jsonmodeler/
│ ├── __init__.py
│ ├── json_modeler.py # Model generator main interface
│ ├── json_parser.py # JSON parser
│ ├── languages/ # Each language support module
│ │ ├── __init__.py
│ │ ├── base.py # Basic language generator class
│ │ ├── cpp.py # C++ Model Builder
│ │ ├── csharp.py # C# Model Builder
│ │ ├── python.py # Python Model Builder
│ │ └── ... # Other language generators
├── tests/
│ ├── __init__.py
│ ├── test_json_parser.py
│ ├── test_model_generator.py
│ └── ... # Other tests
├── scripts/
│ ├── __init__.py
│ ├── convert.py # Command line tools
│ └── ... # Other scripts
├── README.md
├── README_Chinese.md
└── setup.py
Installation
You can install JsonModeler using pip:
pip install jsonmodeler
Usage
Command Line
To use the command-line tool, you can run:
jsonmodeler [-l <language>] <input_file> [-o <output_file>] [--interactive]
-l <language>: Target programming language for model code. Supported languages includecpp,csharp,dart,go,java,js,kotlin,objc,php,python,swift,ts.<input_file>: Path to the input JSON file. If not provided, the tool will read from standard input.-o <output_file>: (Optional) Path to the output file. If not specified, the generated code will be printed to the console.--interactive: Run the tool in interactive mode, allowing you to input parameters step-by-step.
You can use the --help option to view all available command line options:
jsonmodeler --help
Examples
Convert JSON to Python Model Code
jsonmodeler -l python example.json -o output.py
This command converts the JSON data in example.json to Python model code and writes it to output.py.
Convert JSON to Java Model Code and Print to Console
jsonmodeler -l java example.json
This command converts the JSON data in example.json to Java model code and prints the result to the console.
Interactive Mode
jsonmodeler --interactive
This command starts the tool in interactive mode, allowing you to input the target language and JSON data directly.
Using in Python Code
Here's an example of how to use JsonModeler in your Python code:
from jsonmodeler.json_modeler import JsonModeler, Language
# Example usage
model_code = JsonModeler.generate(Language.PYTHON, {
"Person": {
"name": "John",
"age": 30,
"is_student": False
}
})
print(model_code)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jsonmodeler-0.2.2.tar.gz.
File metadata
- Download URL: jsonmodeler-0.2.2.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a73f2f32d98e052d81d596104007a9a5e7ce50e55ffa1dd29359cbdcbac1fdbd
|
|
| MD5 |
72d23af01bf5c1dd96af06813802d83b
|
|
| BLAKE2b-256 |
6ed8098e419bc99bd75964f02e70da08bd71ec88b71a70886ddaa8d57c6e052f
|
File details
Details for the file jsonmodeler-0.2.2-py3-none-any.whl.
File metadata
- Download URL: jsonmodeler-0.2.2-py3-none-any.whl
- Upload date:
- Size: 27.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac539ee21b7cc7f84941b938bcffb5a2b404d1b33bf852eae194b68142b142e6
|
|
| MD5 |
e1d55f82c7626d3df77ead4213c2adb7
|
|
| BLAKE2b-256 |
f2bbc473c53fc1fd5bcf7fd17680bbaccfa2cf39407b32b6d2d7d89ea675063d
|