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

Support for creating a schema from existing JSON or map[string]interface{}/struct #30

Open
brocococonut opened this issue Nov 14, 2021 · 1 comment
Labels
feature request Request to adding a feature

Comments

@brocococonut
Copy link

As the title says, it'd be great to be able to create a schema on the fly from some existing JSON (or a map[string]interface{} or struct with JSON tags)

Some examples of how that might work:

// From struct
type Data struct {
	Name string `json:"name"`
	Key string `json:"key"`
}

data := Data{
	Name: "go",
	Key: "myKey",
}

schema := vjson.NewSchema(
	vjson.Struct(data)
)
// From a map
data := map[string]interface{}{
	"name": "go",
	"key": "myKey",
}

schema := vjson.NewSchema(
	vjson.Map(data)
)
// From a JSON string
data := `{
	"name": "go",
	"key": "myKey"
}`

schema := vjson.NewSchema(
	vjson.JSON(data)
)

All of which would be the equivalent in this case as:

schema := vjson.NewSchema(
	vjson.String("name").Required(),
	vjson.String("key").Required(),
)
@miladibra10
Copy link
Owner

It's an interesting idea.

Right now I'm a little busy and can not implement it right now.

It will be very nice if you contribute and implement this feature yourself. @brocococonut

@miladibra10 miladibra10 added the feature request Request to adding a feature label Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request to adding a feature
Projects
None yet
Development

No branches or pull requests

2 participants