TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Jsonnet – A data templating language

201 pointsby fhrow4484about 6 years ago

31 comments

arianvanpabout 6 years ago
Also check out <a href="https:&#x2F;&#x2F;dhall-lang.org" rel="nofollow">https:&#x2F;&#x2F;dhall-lang.org</a><p>It&#x27;s GCL but with a strong type system and termination guarantees.<p>I personally like the syntax a bit more than jsonnet. It&#x27;s a bit less noisy.<p>I&#x27;m also a bit biased because I work on <a href="https:&#x2F;&#x2F;github.com&#x2F;dhall-lang&#x2F;dhall-kubernetes" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dhall-lang&#x2F;dhall-kubernetes</a> . We&#x27;re currently working on a 2.0 release so the current state of the repo is a bit in turmoil.<p>Programmable configuration language like dhall an jsonet are very powerful and I like them way more than for example helm charts, where templating happens on the string level instead of at the data level.
评论 #19658855 未加载
评论 #19659909 未加载
评论 #19659462 未加载
jpgvmabout 6 years ago
All the people suggesting to use JS instead of Jsonnet are completely missing the point.<p>Jsonnet is a functional lazy evaluated language that supports powerful referential concepts. Unfortunately the website sucks at getting this across.<p>JS on the other hand is an imperative programming language. If you say &quot;use JS&quot; you may as well say &quot;use Python&quot;, the 2 are equivalent in this context and neither are in the same class as Jsonnet in terms of robustness and simplicity.<p>I didn&#x27;t get it until I used it but after using it I don&#x27;t think I would go back to test templating when it comes to dealing with JSON&#x2F;things that are equivalent. i.e I would use Jsonnet to create JSON to convert to YAML rather than templating YAML directly. Same goes for generating objects directly in JS&#x2F;Python&#x2F;jq - yes it can be done, yes sometimes you can write a nice DSL but in most cases Jsonnet is going to allow you to write said DSL faster using functions and it&#x27;s going to be simpler and less prone to errors.
评论 #19658282 未加载
评论 #19661381 未加载
评论 #19658897 未加载
yegleabout 6 years ago
Finally a public version of GCL&#x2F;Borgcfg :-)<p>For people who doesn&#x27;t know, GCL (Generic&#x2F;Google Config Language) is a language that uses dynamic scope. You can define a `template` object with a variable defined as `external`. This way you can create similar objects by providing a concrete value for those `external`s at the time of instantiating.<p>The following paper was referenced in Google&#x27;s borg paper and gives a good overview of the syntax.<p><a href="https:&#x2F;&#x2F;research.tue.nl&#x2F;en&#x2F;studentTheses&#x2F;gcl-viewer" rel="nofollow">https:&#x2F;&#x2F;research.tue.nl&#x2F;en&#x2F;studentTheses&#x2F;gcl-viewer</a>
评论 #19658150 未加载
评论 #19658290 未加载
davidgouldabout 6 years ago
The Lua language was originally a data templateing language [0], and is still very good for that, but like all such things, it grew. Contrary to Greenspun&#x27;s Tenth Rule [1], Lua&#x27;s implementation of Lisp is not at all ad-hoc, informally-specified, bug-ridden, or slow.<p>[0] <a href="https:&#x2F;&#x2F;www.lua.org&#x2F;history.html" rel="nofollow">https:&#x2F;&#x2F;www.lua.org&#x2F;history.html</a><p>[1] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Greenspun%27s_tenth_rule" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Greenspun%27s_tenth_rule</a>
self_awarenessabout 6 years ago
The name might come from a &#x27;sonnet&#x27;, but all I can see is a &#x27;JSON parsing library written for Microsoft .NET&#x27;.
rococodeabout 6 years ago
AllenNLP uses Jsonnet for config files, for anyone ondering what one potential use case is.<p>For example, here&#x27;s a config for NER with ELMo:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;allenai&#x2F;allennlp&#x2F;blob&#x2F;master&#x2F;training_config&#x2F;ner_elmo.jsonnet" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;allenai&#x2F;allennlp&#x2F;blob&#x2F;master&#x2F;training_con...</a><p>I guess the only really jsonnet-specific thing here is std.extVar() call, but generally speaking it&#x27;s just a more flexible JSON file that doesn&#x27;t cost much more to use (brainpower or physical resources). I use it to mix and match configs while debugging sometimes as you can do things like if statements and adding dicts together.<p>It&#x27;s also nice for modularization, you can do things like having a function that returns a dict, so if your config needs two slightly different datareaders you can just pull out all the common parts and call the function twice instead of having two copies of the entire datareader config (with only minor differences).
badtupleabout 6 years ago
There&#x27;s a real need for JSON templating languages not targeting developers.<p>Tools like Zapier, Customer.io&#x27;s webhooks, etc. allow integration with arbitrary APIs and have become a standard part of many marketing&#x2F;sales stacks. These apps use things like Jinja, Mustache, or Liquid which are great for text but not JSON templates.<p>Curly braces as primary delimiters, not allowing trailing commas on final elements, and other features of JSON make generating it a real hassle.<p>Jsonnet is too complex to be that tool, but I&#x27;m glad people are working in the space.
评论 #19659947 未加载
评论 #19658636 未加载
zeliardabout 6 years ago
There&#x27;s also another competing json templating project from google in the works. Doesn&#x27;t seem to be production ready yet, but it&#x27;s open sourced already - <a href="https:&#x2F;&#x2F;github.com&#x2F;cuelang&#x2F;cue" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cuelang&#x2F;cue</a>
c_r_wabout 6 years ago
Some devs from my company just recently published <a href="https:&#x2F;&#x2F;jkcfg.github.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jkcfg.github.io&#x2F;</a>, building on lessons learned from many years of configuring Kubernetes. Since we are discussing JS for config management.
评论 #19657713 未加载
评论 #19657850 未加载
评论 #19657393 未加载
falakiabout 6 years ago
<a href="https:&#x2F;&#x2F;databricks.com&#x2F;blog&#x2F;2018&#x2F;10&#x2F;12&#x2F;writing-a-faster-jsonnet-compiler.html" rel="nofollow">https:&#x2F;&#x2F;databricks.com&#x2F;blog&#x2F;2018&#x2F;10&#x2F;12&#x2F;writing-a-faster-json...</a>
wryunabout 6 years ago
Still plugging json-e over jsonnet, since it&#x27;s valid JSON itself: <a href="https:&#x2F;&#x2F;taskcluster.github.io&#x2F;json-e&#x2F;" rel="nofollow">https:&#x2F;&#x2F;taskcluster.github.io&#x2F;json-e&#x2F;</a>
cwpabout 6 years ago
This is great. I&#x27;ve been looking for something like this and have been considering nix, Starlark and Dhall. This seems to hit a sweet spot between power and familiarity.
评论 #19664182 未加载
arthurzabout 6 years ago
We have just had an article hitting nearly the top on not to use JSON for config <a href="https:&#x2F;&#x2F;arp242.net&#x2F;weblog&#x2F;json_as_configuration_files-_please_dont" rel="nofollow">https:&#x2F;&#x2F;arp242.net&#x2F;weblog&#x2F;json_as_configuration_files-_pleas...</a>
评论 #19657055 未加载
评论 #19657652 未加载
评论 #19657281 未加载
haxterstockmanabout 6 years ago
No thanks I&#x27;ll just write JavaScript
评论 #19656982 未加载
评论 #19656973 未加载
netingleabout 6 years ago
We’ve been using jsonnet to combine Prometheus alerts and Grafana dashboards into little packages called monitoring Mixins: <a href="https:&#x2F;&#x2F;github.com&#x2F;kubernetes-monitoring&#x2F;kubernetes-mixin" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kubernetes-monitoring&#x2F;kubernetes-mixin</a><p>A bunch more exist for things like Prometheus, consul, etc, vault, cluster, ceph, memcached etc<p>We’ve also built a super simple package manager for this called jsonnet-bundler (jb for short).<p>And of course we use jsonnet (with the ksonnet lib) at Grafana Labs for all our Kubernetes jobs.
mafroabout 6 years ago
Why would I use this over, say, Jinja?<p>Do I really want imperative code in my config files? And if so, why not just use vanilla JS?
评论 #19657266 未加载
评论 #19657378 未加载
评论 #19657465 未加载
gfioravabout 6 years ago
I needed a templated language recently (couldn’t do with Mustache methods). Looked at jsonnet but it looked quite abandoned. Ended up finding Json-E [0]. Pretty powerful, and give you the option to pass in methods to the context as to expose them. No support for Async methods, but I wrapped around it with some Promises and did the trick.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;taskcluster&#x2F;json-e" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;taskcluster&#x2F;json-e</a>
bedersabout 6 years ago
If your configuration files are so hard to write that you need to use a templating language that is even harder to write, maybe you need to re-think what a configuration is.
randomcoder1000about 6 years ago
This looks like a public version of gcl&#x2F;borgcfg... But with JavaScript mixed in (so even worse, if that was possible)
评论 #19657486 未加载
nikolayabout 6 years ago
Jsonnet has been around for a while, but it looks like stale. Its stdlib is limited and nonstandard and the whole lazy evaluation is something new developers struggle with. I&#x27;ve been using it at work for 2 years and it&#x27;s sad that it hasn&#x27;t moved much. I think it lost a huge opportunity if it had more active and more open for innovation development. I&#x27;m sorry to say that, but the lead is busy with stuff and is highly opinionated. Also, Jsonnet is slow. We have a few hundred Jsonnet templates and it takes a very long time to compile, which is a pity given it&#x27;s written in C (now being slowly and painfully rewritten in Go for whatever reasons).
okketabout 6 years ago
Previous discussion from 9 months ago: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=17363871" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=17363871</a> (55 comments)
paultopiaabout 6 years ago
I would be interested to hear what heavy lispers think of this. The whole mixing code and data together feels very lispy, albeit with a heavier syntax here... is this sort of a step off from s-expressions, or does it occupy a fundamentally different place?
mafroabout 6 years ago
If there&#x27;s anyone here who has used both dhall and jsonnet in anger, can you comment on your experiences?<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=17529722" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=17529722</a>
bborehamabout 6 years ago
I always want to know what the debugging experience is with any new language. Being side-effect free is cool and all but if I can’t actually figure out why it did A and not B then I’m going to get frustrated.
manigandhamabout 6 years ago
Considering how easy it is to run Javascript anywhere, even small inline statements interpreted dynamically, I can&#x27;t think of a single reason to use this instead.
mullikineabout 6 years ago
It&#x27;s a nice tool to generate json, but then so is jq. I hope to start using it.<p>jsonnet &#x2F;dev&#x2F;stdin &lt;&lt;&lt; &#x27;{x: 1, y: self.x} + {x: 10}&#x27;<p>{&quot;x&quot;:10,&quot;y&quot;:10}
antoineMoPaabout 6 years ago
Configuration is nice, but good defaults are better, and this looks like an invitation to make super complex configurations.
h1dabout 6 years ago
When do you need to use a complex configuration system like this?<p>Aren&#x27;t they supposed to be predefined values?
评论 #19659573 未加载
0xbadcafebeeabout 6 years ago
I have never used a language&#x2F;tool like this at scale and enjoyed it.<p>For example, embedding a bash script in a templating language. This is such an incredibly crap idea I don&#x27;t know how it keeps getting perpetuated. Use of this pattern works as follows: user A writes the script, tests it, shoves it into template. user B modifies the template, commits it, it later breaks silently because it was not tested, because it&#x27;s in a template language, so you can&#x27;t lint it and it has no tests written for it (because how did you know it would even get generated based on your input&#x2F;function, let alone all the places it would be used and how, because templates). user C finds the hidden breakage after tearing out hair, removes the script from template, and writes it as a normal script that takes options and writes a test for good measure. (If you try to use normal dev patterns around the templates, like generate-template-then-commit-to-vcs, relying on and testing the generated versions, your tests have to be reworked whenever you regenerate, and later the generator gradually begins to break, so you just modify the copy in VCS rather than using the template)<p>A separate problem is that templating languages that give you advanced functionality lead you to want to use that functionality, and the more you do, the harder it is to maintain over time. It may not be readily apparent that trying to make Ansible configs work declaratively requires an annoying amount of complexity, or writing entire applications that cannot be easily reused and calling them &quot;modules&quot; or &quot;plugins&quot;. (Whatever you are trying to template&#x2F;generate, the only way to know for sure you&#x27;re doing it validly is to have a function that actually parses and outputs the format according to a spec, because just spitting out a template and then externally validating it becomes very difficult to debug, because you don&#x27;t know why the template is spitting out the output the way it is. So your templating language eventually becomes a compiler)<p>Since this is a new language, you also have to re-implement everything you normally have for a language, like a plug-in for your IDE, linter, debugger, code analyzer, port the standard libraries to different systems, etc. And of course all new devs have to learn this thing and all its quirks before they can start doing work. An entire ecosystem eventually needs to exist to support its continued use, and if you have problems, you hope this ecosystem continues to flourish so you can get support for this unsupported language tool thing, or you&#x27;ll be hiring internal devs to do it.<p>Maybe the problem is these start out as tools for developers, and only when they get used for operations do the anti-patterns surface. I&#x27;ve gone through it several times and it always ends up a PITA.
评论 #19659517 未加载
mshahi8210about 6 years ago
Lua is also good for same purpose.
sheeshkebababout 6 years ago
Ehh... this feels ugly and dirty (not that js code for generating similar json files is typically any better)