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

Allow for marshalling schema to JSON for storage #31

Closed
brocococonut opened this issue Nov 15, 2021 · 2 comments · Fixed by #33
Closed

Allow for marshalling schema to JSON for storage #31

brocococonut opened this issue Nov 15, 2021 · 2 comments · Fixed by #33

Comments

@brocococonut
Copy link

Having the ability to convert a properly formatted JSON string into a schema is great. But it'd work better if the reverse were also possible. Currently if you try to run a schema through json.Marshal, you get something similar to this:

schema := vjson.NewSchema(
	vjson.Float("i").Required(),
	vjson.Array("children", vjson.String("item")),
)

byteStr, _ := json.Marshal(schema)

println(string(byteStr)) // Output: [{},{}]

Having complimentary functions to vjson.ReadFromBytes(), vjson.ReadFromString(), vjson.ReadFromFile() such as schema.WriteToString(...), schema.WriteToBytes(...), and schema.WriteToFile(...) would enable the proper backing up and restoring of these schemas.

@miladibra10
Copy link
Owner

I will review the PR ASAP.

@miladibra10 miladibra10 linked a pull request Oct 18, 2022 that will close this issue
@miladibra10
Copy link
Owner

Dear @brocococonut
Your requested feature is implemented. you can use json.Marshal method in the standard library in order to create a backup of your schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants