datamodel-code-generator
datamodel-code-generator copied to clipboard
When generating pydantic with jsonData, an error occurred: "Invalid file format"
Describe the bug When generating pydantic with jsonData, an error occurred: "Invalid file format"
To Reproduce
Example schema:
- json file:douyin.json
Used commandline:
$ datamodel-codegen --input douyin.json --input-file-type json --output model.py
Expected behavior Invalid file format
Version:
- OS: windows10
- Python version: 3.11.1
- datamodel-code-generator version: 0.25.6
Additional context
可能是编码问题,中文默认系统编码是gbk,而你的json可能是utf-8。你可以尝试以gbk保存后再试。 It might be a problem with file encoding. The datamodel-codegen loads your json file with the system default encoding (GBK in simplified chinese env) and it failed. Try save it with GBK encoding and run the code-gen command again.
I had the same problem with my json files (and docs from mongo) - I dunno why but somewhere in the code yaml file reader is used and it throws errors when encouters specific unicode. Made a gist with script I use to clean json from those characters and generate pydantic class.