Closed jadehopepunk closed 2 months ago
This question is kind of broad. Have you gone through our turorial?
Also, take a read through module output in our language reference.
Sorry, you're quite right, I was being vague.
To be specific, I'm trying to serialize in code, not using a command line too. For example, here's my generated go code: https://github.com/merri-bek-tech/participatory-ops/blob/main/paropd/config/computed/ComputedConfig.pkl.go
It handily generates Load methods for me. It'd be nice if it also generated a Save method.
But, even failing that, if I have the struct that I loaded from the pkl file, in my case a ComputedConfig
, I can't figure out how to serialise that into a string of any sort.
I don't see any mention of that in the tutorial, and the module output section makes very little sense to me. I'm expecting to see how to do the output in the client library for my particular language (go in this case), not in pkl files. Perhaps I'm thinking of pkl the wrong way.
That's not what our language bindings are for, ordinarily. What would you expect to write these values out as? Pkl code? Yaml? JSON? Some bespoke binary format? Pkl isn't itself a static format (like JSON / YAML / Protobuf), so Load -> Change -> Save would be incredibly lossy on the first round (because Load evaluates all dynamic contents into static contents).
If you want to write these values as JSON, YAML, or some other format, you can add struct tags to the generated code:
https://pkl-lang.org/go/current/codegen.html#struct-tags
Writing out Pkl code isn't a very well supported route right now, as Phil mentioned.
Thanks for the help folks, I'm closing this off. I think the disconnect is that isn't the tool that I need if I'm just wanting to read/write a config file with schema checking.
I can't find anything in the docs or code about serializing the objects I loaded using pkl.