You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+77-16Lines changed: 77 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -122,24 +122,79 @@ python setup.py install
122
122
123
123
### CLI
124
124
125
-
For regular usage CLI tool is a best option. After you install this package you could use it as `json2models`
126
-
or `python -m json_to_models`.
125
+
For regular usage CLI tool is the best option. After you install this package you could use it as `json2models <arguments>`
126
+
or `python -m json_to_models <arguments>`. I.e.:
127
+
```
128
+
json2models -m Car car_*.json -f attrs > car.py
129
+
```
127
130
128
131
Arguments:
129
-
130
-
| Key | Format | Description | Example | Note |
131
-
| --- | --- | --- | --- | --- |
132
-
|`-h, -help`| - | show help message and exit |||
133
-
|`-m, --model`|`-m <Model name> [<JSON files> ...]`| Model name and its JSON data as path or unix-like path pattern. `*`, `**` or `?` patterns symbols are supported. |`-m Car audi.json reno.json` or `-m Car audi.json -m Car reno.json` (results will be the same) ||
134
-
|`-l, --list`|`-l <Model name> <JSON key> <JSON file>`| Like `-m` but given json file should contain list of model data (dataset). If this file contains dict with nested list than you can pass `<JSON key>` to lookup. Deep lookups are supported by dot-separated path. If no lookup needed pass '-' as <JSONkey> |`-l Car - cars.json -l Person fetch_results.items.persons result.json`| Models names under `-l` arguments should be unique |
135
-
|`-f, --framework`|`-f {base,attrs,dataclasses,custom}`| Model framework for which python code is generated. 'base' (default) mean no framework so code will be generated without any decorators and additional meta-data. |`-f attrs`| Default: `-f base`|
|`--datetime`| - | Enable datetime/date/time strings parsing. Warn.: This can lead to 6-7 times slowdown on large datasets. Be sure that you really need this option. || Default: disabled |
138
-
|`--merge`|`--merge MERGE_POLICY [MERGE_POLICY ...]`| Merge policy settings. Possible values are: `percent[_<percent>]` - two models had a certain percentage of matched field names. Custom value could be i.e. `percent_95`. `number[_<number>]` - two models had a certain number of matched field names. `exact` - two models should have exact same field names to merge. |`--merge percent_95 number_20` - merge if 95% of fields match or 20 fields match | Default: `--merge percent_70 number_10`|
139
-
|`--dict-keys-regex, --dkr`|`--dkr RegEx [RegEx ...]`| List of regular expressions (Python syntax). If all keys of some dict are match one of them then this dict will be marked as dict field but not nested model. |`--dkr node_\d+ \d+_\d+_\d+`|`^` and `$` (string borders) tokens will be added automatically but you have escape to other special characters manually. | Optional |
140
-
|`--dict-keys-fields, --dkf`|`--dkf FIELD_NAME [FIELD_NAME ...]`| List of model fields names that will be marked as dict fields |`--dkf "dict_data" "mapping"`| Optional |
141
-
|`--code-generator`|`--code-generator CODE_GENERATOR`| Absolute import path to GenericModelCodeGenerator subclass. |`-f mypackage.mymodule.DjangoModelsGenerator`| Is ignored without `-f custom` but is required with it |
142
-
|`--code-generator-kwargs`|`--code-generator-kwargs [NAME=VALUE [NAME=VALUE ...]]`| List of GenericModelCodeGenerator subclass arguments (for `__init__` method, see docs of specific subclass). Each argument should be in following format: `argument_name=value` or `"argument_name=value with space"`. Boolean values should be passed in JS style: `true` or `false`|`--code-generator-kwargs kwarg1=true kwarg2=10 "kwarg3=It is string with spaces"`| Optional |
132
+
*`-h`, `--help`
133
+
* Show help message and exit
134
+
135
+
*`-m`, `--model`
136
+
***Format**: `-m <Model name> [<JSON files> ...]`
137
+
***Description**: Model name and its JSON data as path or unix-like path pattern. `*`, `**` or `?` patterns symbols are supported.
138
+
***Example**: `-m Car audi.json reno.json` or `-m Car audi.json -m Car reno.json` (results will be the same)
0 commit comments