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 example for Serde deserialisation #142

Open
Timmmm opened this issue Dec 14, 2023 · 4 comments
Open

Add example for Serde deserialisation #142

Timmmm opened this issue Dec 14, 2023 · 4 comments

Comments

@Timmmm
Copy link

Timmmm commented Dec 14, 2023

I think most people using the Rust library version of this would want to just take serde-json code and switch it to jsonnet. Unfortunately I can't figure out how to do that. An example would be great! (I assume it is possible.)

@bruno-delfino1995
Copy link
Contributor

bruno-delfino1995 commented Dec 14, 2023

@Timmmm, in the meantime, you can look at this snippet from a project using this library. I hope it helps!

@Timmmm
Copy link
Author

Timmmm commented Dec 18, 2023

I was more thinking something like the example in json5's readme. Is something like that possible?

@CertainLach
Copy link
Owner

It is possible, but jsonnet is much more powerful than json5, and should not be/not intended to be used like serde_json.

Configuration may include other files (and assuming current directory to be CWD is bad and insecure), then there is more types available than serde-json supports, I.e functions. Also, most of the time you want to supply jsonnet with tla/ext vars and so on.

@Timmmm
Copy link
Author

Timmmm commented Dec 18, 2023

My understanding was that the result of executing a Jsonnet file would be an ordinary JSON data object. So there must be a way to execute it and then load that with serde? For my current use case ("better JSON") I don't want to supply tla/ext vars or any custom functions or whatever.

and assuming current directory to be CWD is bad and insecure

Agreed, I'd say any API should require explicitly setting the current directory and error on loading external files if you didn't. Otherwise it's not fail-safe (c.f. yaml.safe_load()!)

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

No branches or pull requests

3 participants