Originally created by @derphilipp on GitHub (Jun 25, 2024).
Is it possible to achive:
Write a pkl template to validate types
Write a Go(lang) program that reads an already existing json file and validate it with the help of the pkl template file
This way golang programs could harness the power of pkl without modifying the user expirience / config files of existing tools
Originally created by @derphilipp on GitHub (Jun 25, 2024).
Is it possible to achive:
- Write a pkl template to validate types
- Write a Go(lang) program that reads an already existing json file and validate it with the help of the pkl template file
This way golang programs could harness the power of pkl without modifying the user expirience / config files of existing tools
[aside: I'd prefer questions like this under Discussions]
Yes. You don't even need to write a Go program for the validation. That said, I think our editing experience is better than most JSON experiences. I guess "existing tools" might be a deal-breaker. Anyway, yes, you can always add the following to any template;
import "pkl:json"
import "package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.deepToTyped@1.0.2#/deepToTyped.pkl"
output {
value = deepToTyped.apply(module.getClass(), new json.Parser {}.parse(read(read("prop:JsonPath"))))
}
Now, if you invoke Pkl with a value for external property JsonPath to point to your .json file, you can consume output.value as an instance of the module it's defined in.
@holzensp commented on GitHub (Jun 25, 2024):
[aside: I'd prefer questions like this under Discussions]
Yes. You don't even need to write a Go program for the validation. That said, I think our editing experience is better than most JSON experiences. I guess "existing tools" might be a deal-breaker. Anyway, yes, you can always add the following to any template;
```
import "pkl:json"
import "package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.deepToTyped@1.0.2#/deepToTyped.pkl"
output {
value = deepToTyped.apply(module.getClass(), new json.Parser {}.parse(read(read("prop:JsonPath"))))
}
```
Now, if you invoke Pkl with a value for external property `JsonPath` to point to your `.json` file, you can consume `output.value` as an instance of the module it's defined in.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @derphilipp on GitHub (Jun 25, 2024).
Is it possible to achive:
This way golang programs could harness the power of pkl without modifying the user expirience / config files of existing tools
@holzensp commented on GitHub (Jun 25, 2024):
[aside: I'd prefer questions like this under Discussions]
Yes. You don't even need to write a Go program for the validation. That said, I think our editing experience is better than most JSON experiences. I guess "existing tools" might be a deal-breaker. Anyway, yes, you can always add the following to any template;
Now, if you invoke Pkl with a value for external property
JsonPathto point to your.jsonfile, you can consumeoutput.valueas an instance of the module it's defined in.@derphilipp commented on GitHub (Jun 25, 2024):
Thank you very much and you are absolutely right, this should be under 'Discussion'!