Jsonnet – A data templating language
jsonnet.org
jsonnet.org
Is this going full circle then? JS -> JSON -> JS.
More seriously and like someone already said, to many brackets and quotes for rapid prototyping.
The 1st party bindings are for C, Go and Python; so it a cross-language JSON DSL. And making it a strict DSL has significant advantages.
I have threatened to write a Terraform equivalent in Lisp every time Terraform frustrated me, which was often.
{
person: self.person,
}
RUNTIME ERROR: max stack frames exceeded.
{
"self": "a",
b: self.self
}
STATIC ERROR, expected token identifier but got self
Looks good.For comparison, reader variables in Common Lisp:
CL-USER> (setf *print-circle* t)
T
CL-USER> '#1=(person . #1#)
#1=(PERSON . #1#)https://plugins.jetbrains.com/plugin/10852-jsonnet
Gives you syntax highlighting and basic jump-2-definition, though more advanced features are TODO.
You can still helm-ify a ksonnet app.
At a prior job we created extremely large, complicated CloudFormation templates in JSON that could have been made much simpler with Jsonnet and the ability to do comprehension and some other tricks to keep it DRY. A coworker ended up writing a bunch of Python scripts to templatize the CF templates (ugh).
At my current job we ended up using Jsonnet as a configuration language for Apache Aurora jobs [1], which was also helpful when trying to make it easy for others to pick it up and create their own jobs from base templates.
That being said, it can be frustrating to get going with and for some cases I do find myself having to trace through things very carefully in order to to figure out exactly what's going on.
You could also go to town with reader macros in Lisp or use Racket.
I mention this not to be pedantic, but in case it helps another coder from wasting a couple days chasing a bug like I once had to, when I thought I could template raw JSON into a script file to make some server-side data available as a global var on in the browser.
XSLT was brilliant except it was extremely verbose and difficult to use due to wanting to be expressed in XML.
XSLT as prior art demonstrates that Jsonnet made the right choice here.
For example, merging two objects is trivial in jsonnet yet pretty close to impossible in jinja2.
{{ merge(foo, bar)|tojson|safe }}
Even something polymorphic to render a template, then merge into a known dict, then output json would be easy. A signature that might look like: {{ render_json_dict(foo, "foo.json")|merge(bar)|tojson|safe. }}In the last jsonnet template I wrote, I merged a few keys into the top level, merged a few keys into a deeper level, and added some random characters to the end of a string value to make it unique. Trivial in jsonnet.
Disagree. In my experience the trend is in the opposite direction: ASI is broadly acknowledged to cause problems, CoffeeScript turned out to be a trainwreck, and popular defaults for linters tend to enforce semicolons.
Q: How can you conveniently and compactly represent, view and edit JSON in spreadsheets, using the grid instead of so much punctuation?
I’ve come up with a simple format and convenient conventions for representing and editing JSON in spreadsheets, without any sigils, tabs, quoting, escaping or trailing comma problems, but with comments, rich formatting, formulas, and leveraging the full power of the spreadsheet.
It's a work in progress, and I have posted a few messages about it on HN. I'm in the process of writing it up now on Medium (but I'll publish it now so you can read it). I welcome any feedback, criticisms and suggestions, please!
https://medium.com/@donhopkins/representing-and-editing-json...
https://news.ycombinator.com/item?id=17309132 https://news.ycombinator.com/item?id=17360071 https://news.ycombinator.com/item?id=17360799 https://news.ycombinator.com/item?id=17360883
Here's an example spreadsheet -- check out the examples in the different sheets (the tabs along the bottom):
https://docs.google.com/spreadsheets/d/1nh8tlnanRaTmY8amABgg...
Here's a sample implementation, that runs in the browser, node.js, as a Google Spreadsheet extension, etc:
https://github.com/SimHacker/UnityJS/blob/master/UnityJS/Ass...
As well as parsing JSON structures out of raw spreadsheet data, that code also returns a tree of scopes that you can use for syntax coloring or error message feedback, because I'm integrating it with Google Sheets (but the parser is independent of the particular spreadsheet, and just operates on 2D array of strings).
It would be nice to develop it into a macro templating engine for JSON (or higher level structures that happen to be represented as JSON). Kind of like Genshi (the XML/Python templating system that I’ve used a whole lot and love for its simplicity).
https://www.wired.com/1996/11/es-marimba/
http://www.suck.com/netmoguls/96/10/18/front.html
http://www.suck.com/netmoguls/96/10/18/back.html
Kim said: "It was fun naming stuff back then. You could actually get the trademark/website!"