4 ms·
Why would I use this over, say, Jinja? Do I really want imperative code in my config files? And if so, why not just use vanilla JS?
by mafro 7y ago
Why would I use this over, say, Jinja?
Do I really want imperative code in my config files? And if so, why not just use vanilla JS?
- weberc2 7y agoJinja is a text templating language. A valid ninja template may not produce valid JSON/YAML/etc. Sometimes you need more power than a config language gives you, specifically when you want reuse. Helm uses something like jinja, but the template files are often complex and messy (and they are looking into supporting Lua to deal with these problems). CloudFormation built function semantics on top of JSON/YAML twice: once in the form of templates and again in the form of its intrinsic functions. Skycfg uses the starlark language to output YAML, and this is the best approach since it has the right semantics and uses a familiar language (starlark is stripped down Python).
- fiatjaf 7y agoWhy not jq, then?
- danielhlockard 7y agojq is a json parsing tool, no?
- roganartu 7y agoA very powerful one. You could in theory stream multiple files into jq and have it output effectively arbitrary JSON based on their contents since it supports conditionals. I don't think it would be very pretty since it's not designed for that use case, but the jq language is certainly powerful enough to allow it.
- fiatjaf 7y agoIt can be used to generate JSON using functions, input data, conditional expressions and anything you want.
- babo 7y agoWith a deep enough JSON structure with similar enough items, the jq expressions are hard to make or maintain. This is a real world example: jq '.sourceSelectionTrees[].rootNode.children[].children' | jq '.[]? | .action.attributeMapping.attributeSources' | jq -r '.[]? | select(.type == "XYZ") | .dataRef.id'
- cle 7y agoWhy don't you take a look at the link? It has a page specifically addressing these questions: https://jsonnet.org/articles/comparisons.html https://jsonnet.org/articles/comparisons.html
- atombender 7y agoJsonnet is much easier to make secure than JS. Untrusted JS needs to be run in a sandbox, can be insecure and contain side effects (e.g. read from the file system). Jsonnet can be statically guaranteed to not just be safe, but side-effect-free.