CertainLach/jrsonnet

Add example for Serde deserialisation

Timmmm opened this issue · 4 comments

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

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

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

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.

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()!)