Live data from Hacker News

Jsonnet – A data templating language

jsonnet.org

21–30 of 90 posts

Re: Jsonnet – A data templating language

#23
post #10

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?

Jsonnet 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.

Re: Jsonnet – A data templating language

#25

This looks like a public version of gcl/borgcfg... But with JavaScript mixed in (so even worse, if that was possible)

Jsonnet does not have JavaScript, though. It's JavaScript-like, but not nearly as complex (e.g. no prototypes, classes, etc.).

Re: Jsonnet – A data templating language

#26
post #3

No thanks I'll just write JavaScript

Exactly my thoughts. I don’t see how it’s better than JS or TypeScript. I can render any object into JSON. This is in fact how I manage Kubernetes manifests. I use this package: https://www.npmjs.com/package/kubernetes-models Then I write normal TypeScript code to create Kubernetes objects/resources. Then I render it to JSON and feed to kubectl. The beauty of this solution is that it’s OOP and DRY.

You're assuming that all code can be trusted. Jsonnet is much easier to make secure than JS, since it can be statically guaranteed to be safe and side-effect-free (e.g. can't access the file system). This permits evaluating arbitrary untrusted data, which can be a boon to systems like CI servers, databases, or even Kubernetes (think Helm charts).

Re: Jsonnet – A data templating language

#28
AllenNLP uses Jsonnet for config files, for anyone ondering what one potential use case is.

For example, here's a config for NER with ELMo:

https://github.com/allenai/allennlp/blob/master/training_con...

I guess the only really jsonnet-specific thing here is std.extVar() call, but generally speaking it's just a more flexible JSON file that doesn'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.

It'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).

Re: Jsonnet – A data templating language

#30
post #3

Earlier quoted context omitted.

Exactly my thoughts. I don’t see how it’s better than JS or TypeScript. I can render any object into JSON. This is in fact how I manage Kubernetes manifests. I use this package: https://www.npmjs.com/package/kubernetes-models Then I write normal TypeScript code to create Kubernetes objects/resources. Then I render it to JSON and feed to kubectl. The beauty of this solution is that it’s OOP and DRY.

You're assuming that all code can be trusted. Jsonnet is much easier to make secure than JS, since it can be statically guaranteed to be safe and side-effect-free (e.g. can't access the file system). This permits evaluating arbitrary untrusted data, which can be a boon to systems like CI servers, databases, or even Kubernetes (think Helm charts).

He is producing JSON, just as you said. Not sure you understood him.

He has a TS script that outputs JSON, which he is using as config.

Post reply on HN