jrsonnet icon indicating copy to clipboard operation
jrsonnet copied to clipboard

Add example for Serde deserialisation

Open Timmmm opened this issue 2 years ago • 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 avatar Dec 14 '23 14:12 Timmmm

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

bruno-delfino1995 avatar Dec 14 '23 19:12 bruno-delfino1995

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

Timmmm avatar Dec 18 '23 13:12 Timmmm

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.

CertainLach avatar Dec 18 '23 15:12 CertainLach

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

Timmmm avatar Dec 18 '23 15:12 Timmmm