Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter to add the values from json as default values in the model #40

Open
teodor-t-tenev opened this issue Oct 19, 2021 · 1 comment
Labels
CLI Command line agruments and related code enhancement New feature or request wontfix This will not be worked on

Comments

@teodor-t-tenev
Copy link

Describe

It would be great if there is an option to add the values from json as default values in the Model

Reproduce (Optional)

Package version: ...

JSON data:

{
  "name": "John Smith",
  "hometown": {
    "name": "New York",
    "id": 123
  }
}
...

Desired result

A clear and concise description of what you want to happen.
Class code:

r"""
generated by json2python-models v0.2.4 at Tue Oct 19 22:08:54 2021
command: /Users/teodor.tenev/PycharmProjects/TestProj/venv/bin/json2models -m Car package.json -f dataclasses
"""
from dataclasses import dataclass, field
from typing import Literal

@dataclass
class Hometown:
    name: Literal["New York"] = 'New York'
    id_: int = 123

@dataclass
class Car:
    hometown: 'Hometown' = Hometown()
    name: Literal["John Smith"] = 'John Smith'
...
@teodor-t-tenev teodor-t-tenev added the enhancement New feature or request label Oct 19, 2021
@bogdandm
Copy link
Owner

This project is designed to generate models from large json datasets. So default value could be generated only when there is just one value for given field in whole dataset. In my opinion this is not very common case. Also currently there is no logic to track non-string values.
So for now I will not plan to implement it. But PR are always welcome. Just do not break existing tests and logic and provide option to disable this feature.

@bogdandm bogdandm added the wontfix This will not be worked on label Sep 13, 2022
@bogdandm bogdandm added the CLI Command line agruments and related code label Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI Command line agruments and related code enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants