mirror of
https://github.com/wassname/prob_jsonformer.git
synced 2026-09-10 12:37:35 +08:00
add example
This commit is contained in:
@@ -53,6 +53,47 @@ generated_data = jsonformer()
|
||||
print(generated_data)
|
||||
```
|
||||
|
||||
### Jsonformer works on complex schemas, even with tiny models. Here is an example of a schema with nested objects and arrays, generated by a 3B parameter model.
|
||||
|
||||
```python
|
||||
{"type": "object", "properties": {"car": {"type": "object", "properties": {"make": {"type": "string"}, "model": {"type": "string"}, "year": {"type": "number"}, "colors": {"type": "array", "items": {"type": "string"}}, "features": {"type": "object", "properties": {"audio": {"type": "object", "properties": {"brand": {"type": "string"}, "speakers": {"type": "number"}, "hasBluetooth": {"type": "boolean"}}}, "safety": {"type": "object", "properties": {"airbags": {"type": "number"}, "parkingSensors": {"type": "boolean"}, "laneAssist": {"type": "boolean"}}}, "performance": {"type": "object", "properties": {"engine": {"type": "string"}, "horsepower": {"type": "number"}, "topSpeed": {"type": "number"}}}}}}}, "owner": {"type": "object", "properties": {"firstName": {"type": "string"}, "lastName": {"type": "string"}, "age": {"type": "number"}}}}}
|
||||
```
|
||||
|
||||
```python
|
||||
{
|
||||
car: {
|
||||
make: "audi",
|
||||
model: "model A8",
|
||||
year: 2016.0,
|
||||
colors: [
|
||||
"blue"
|
||||
],
|
||||
features: {
|
||||
audio: {
|
||||
brand: "sony",
|
||||
speakers: 2.0,
|
||||
hasBluetooth: True
|
||||
},
|
||||
safety: {
|
||||
airbags: 2.0,
|
||||
parkingSensors: True,
|
||||
laneAssist: True
|
||||
},
|
||||
performance: {
|
||||
engine: "4.0",
|
||||
horsepower: 220.0,
|
||||
topSpeed: 220.0
|
||||
}
|
||||
}
|
||||
},
|
||||
owner: {
|
||||
firstName: "John",
|
||||
lastName: "Doe",
|
||||
age: 40.0
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Bulletproof JSON generation: Jsonformer ensures that the generated JSON is always syntactically correct and conforms to the specified schema.
|
||||
@@ -67,8 +108,6 @@ pip install jsonformer
|
||||
|
||||
## Development
|
||||
|
||||
<!-- https://python-poetry.org/docs/#installation -->
|
||||
|
||||
[Poetry](https://python-poetry.org/docs/#installation) is used for dependency management.
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user