Live data from Hacker News

Jsonnet – A data templating language

jsonnet.org

61–70 of 90 posts

Re: Jsonnet – A data templating language

#61
post #50

There's a real need for JSON templating languages not targeting developers. Tools like Zapier, Customer.io's webhooks, etc. allow integration with arbitrary APIs and have become a standard part of many marketing/sales stacks. These apps use things like Jinja, Mustache, or Liquid which are great for text but not JSON templates. Curly braces as primary delimiters, not allowing trailing commas on final elements, and oth…

What is it about "curly braces as primary delimiters" that you think is a hassle? What would you suggest instead?

It is easy to get confused whether a brace is part of the json or part of the mustache/handlebars/etc.

  {
    "hello": {"{{place}}":{{{#items}}"{{thing}}":{{n}},{{/items}}}},  
    "urls": [{{#items}}"{{url}}",{{/items}}]
  }

It's unambigious and can be reasoned through, but it's certainly hard to tell what structure the template is building at a glance. This is not a complex or contrived example.

Syntax highlighting, linters, proper indentation, etc. all help...but when talking about non-programmers who aren't used to this it's an incredible hurdle. People are also lazy and error prone, so you can't rely on indentation to make things clear, especially since it's not always clear how you should indent nesting of the template vs nesting of the json datastructure you're trying to build.

Most modern templating languages have a config option for changing the delimeter. Setting it to something like (( or It's also worth pointing out that the above template generates subtly incorrect json with trailing commas. In pure mustache it's not possible to get rid of that trailing comma. You have to either change your data (add a "last":true key to the last element of any arrays), or have some kind of post-processing step.

All of the existing solutions are workable, they just aren't ideal.

Re: Jsonnet – A data templating language

#62
post #39

Finally a public version of GCL/Borgcfg :-) For people who doesn't know, GCL (Generic/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. The following paper was referenced in Google's borg paper and gives a good…

Maybe it’s because I’m not a top 1% intelligence that I don’t get this but under what circumstances would configurations become complex enough to where this becomes necessary?

IMO this would mostly be useful if you had an architecture that evolved over time where you started with flat files for configuration and later moved to a centralized configuration system, many of which have concepts of references. Duplicating configuration or tapping into some of the advanced functions in here isn’t super helpful when you’re purely dealing with flat files, but this becomes helpful if you’re combining it with some synced external state because you can use this to “smooth over” differences in data shape.

Re: Jsonnet – A data templating language

#63

Also check out https://dhall-lang.org It's GCL but with a strong type system and termination guarantees. I personally like the syntax a bit more than jsonnet. It's a bit less noisy. I'm also a bit biased because I work on https://github.com/dhall-lang/dhall-kubernetes . We're currently working on a 2.0 release so the current state of the repo is a bit in turmoil. Programmable configuration language like dhall an json…

Can dhall be compiled for Windows?

Re: Jsonnet – A data templating language

#64

I have never used a language/tool like this at scale and enjoyed it. For example, embedding a bash script in a templating language. This is such an incredibly crap idea I don'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'…

Tools like jsonnet and dhall exist to address the very problems you have called out. You may want to give them a closer look.

Re: Jsonnet – A data templating language

#66
post #57

When do you need to use a complex configuration system like this? Aren't they supposed to be predefined values?

https://gocd.io/ allows you store CI/CD pipeline configuration in a git repository.

If you have many different components, you really want to factor out common things into templates (like build, deploy), with the option to disable some stages (some components might not have end-to-end tests, for example), plug in some values etc.

I've long been on the lookout for a template system for data structures for this use case, so I'll take a look at some of the suggestions in this thread.

Re: Jsonnet – A data templating language

#67
post #54

Also check out https://dhall-lang.org It's GCL but with a strong type system and termination guarantees. I personally like the syntax a bit more than jsonnet. It's a bit less noisy. I'm also a bit biased because I work on https://github.com/dhall-lang/dhall-kubernetes . We're currently working on a 2.0 release so the current state of the repo is a bit in turmoil. Programmable configuration language like dhall an json…

Just my two cents but I would go against the first interaction with the user being find the bug, I didn't didn't find it and missed the point, granted I didn't take much time and I'm on mobile, but I guess that's the reality for many people if not most :)

The typo is in the name bill in the value of publicKey. I assume this is a way to introduce the user to definitions that help you avoid these kind of mistakes. I think it would be more suitable as a use case description rather than an exercise for the user.

Re: Jsonnet – A data templating language

#68
post #56
post #36

All the people suggesting to use JS instead of Jsonnet are completely missing the point. Jsonnet is a functional lazy evaluated language that supports powerful referential concepts. Unfortunately the website sucks at getting this across. JS on the other hand is an imperative programming language. If you say "use JS" you may as well say "use Python", the 2 are equivalent in this context and neither are in the same cla…

JS is a lot closer to Scheme and Lisps than an imperative language. In fact, it used to have a lispy syntax before Brenden Eich was forced to change it to make it more approachable.

It's not. http://journal.stuffwithstuff.com/2013/07/18/javascript-isnt...

Re: Jsonnet – A data templating language

#69
post #39

Finally a public version of GCL/Borgcfg :-) For people who doesn't know, GCL (Generic/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. The following paper was referenced in Google's borg paper and gives a good…

Maybe it’s because I’m not a top 1% intelligence that I don’t get this but under what circumstances would configurations become complex enough to where this becomes necessary?

Let's say you manage a public GCP product. You need to run your job in multiple data center. Naturally the data center name is different between each Job object. You should only define one template and then substitute the data center name in the object.

But wait the product have multiple regions. For each region we will depend on regionalized database etc to improve reliability. We need to have some sort of "mixin" so that certain command line arguments can be consistently applied to all jobs in that region.

And then SWE want to rollout a new feature, as the first step they want to roll it out in one data center first then move to full prod later. Now you need to have a data center level overrides.

Can all of these be done in a generic programming language? Yes sure, but why not use a language that intentionally limit what you can do, is almost side effect free?

Re: Jsonnet – A data templating language

#70

Also check out https://dhall-lang.org It's GCL but with a strong type system and termination guarantees. I personally like the syntax a bit more than jsonnet. It's a bit less noisy. I'm also a bit biased because I work on https://github.com/dhall-lang/dhall-kubernetes . We're currently working on a 2.0 release so the current state of the repo is a bit in turmoil. Programmable configuration language like dhall an json…

GCL doesn't have an equivalent of let-expression though, this makes it less like writing GCL.

Alternatively nix expression is also close enough: https://nixos.org/nix/manual/#chap-writing-nix-expressions

Post reply on HN