Space and special characters in keys
See original GitHub issueIn our project we process a large number of JSON files from external source. We want to use pydantic for data models and also to check the structure of incoming files. The JSON files has spaces and special characters in the keys.
Example:
{
"Serial Number": "A12345678",
"Timestamp": "2020-05-26T12:15:25.792741Z",
"Data": {
"Length (m)": 12.34,
"Symmetric deviation (%)": 12.216564148290807,
"Total running time (s)": 974,
"Mass (kg)": 42.23,
"Initial parameters": {
"V1": 123,
"V2": 456
}
}
}
The keys with space and brackets works perfect. They are generated as Length__m_: float = Field(..., alias='Length (m)')
for example.
The generator don’t likes the “Data.Initial parameters” key in the example above. It is the name of the sub structure and would result in a class name with space The following error is raised:
black.InvalidInput: Cannot parse: 6:14: class Initial parameters(BaseModel):
It would be cool, if the generator would support such files. Is this possible to add this feature?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Special Characters - Make Office Work
Special Characters describes symbols and nonprinting characters that are inserted from the Symbol dialog box or applicable shortcut key and lists the codes ......
Read more >Special Characters
Available option keys are Alt + 1 through Alt + 4. Click the special character you want to assign to a shortcut key....
Read more >Alt Codes – How to Type Special Characters and Keyboard ...
In Windows, you can type any character you want by holding down the ALT key, typing a sequence of numbers, then releasing the...
Read more >Whitespace character - Wikipedia
In computer programming, whitespace is any character or series of characters that represent horizontal or vertical space in typography. ... a special "exact...
Read more >How to replace white space and remove special characters ...
In order the "clean" the keys you need to use 2 regexs: .replace(/\s+/g, '_') which will replace whitespace chars into _ .replace(/\W+/g, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve tested it now, works perfectly now. Thank your very much.
@fzirker Thank you for writing detail about the problem.
I have understood. I will re-use converting logic of field name for generating model name. I’m sorry, I have some tasks. I want to implement this issue in this week or next week.