4 ms·
There's a real need for JSON templating languages not targeting developers. Tools like Zapier, Customer.io's webhooks, etc. allow integration with arbitrary AP
by badtuple 7y ago
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 other features of JSON make generating it a real hassle.
Jsonnet is too complex to be that tool, but I'm glad people are working in the space.
- nfoz 7y agoWhat is it about "curly braces as primary delimiters" that you think is a hassle? What would you suggest instead?
- rmetzler 7y agoCurly braces on US Layout keyboards are fine, they just need to be balanced. On keyboards with German layout curly braces are really hard to type and on Mac keyboards with German layout they are not even marked. So I don’t think any programmer can work with such a layout, yet many people do exactly that.
- badtuple 7y agoIt 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 << might help differentiate things a bit, but then you're throwing away easy use of examples, documentation, stack overflow questions, and so much more that already exists for that language. That documentation and copy-pastable community help is not something to throw away lightly if you're designing a tool for this audience. 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.
- UncleEntity 7y agoI hacked together a asdl parser in boost::spirit a while back that used mustache to generate the C++ AST (which was then used to generate its own AST to make sure it all worked) and can attest the curly braces in the templates were a righteous PITA to get right. If I had to do it all over again I'd probably use the config option and change them to something like '(.', '.)' that doesn't naturally occur in the output language.
- PretzelFisch 7y agoIt's just my gut feeling but for nondevelopers, the config storage doesn't matter as long as there is a good GUI to generate what they need to save or paste into another system.