question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Space and special characters in keys

See original GitHub issue

In 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
fzirkercommented, Jul 1, 2020

I’ve tested it now, works perfectly now. Thank your very much.

2reactions
koxudaxicommented, Jun 16, 2020

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found