8 ms·
Jsonnet – A data templating language
- isuckatcoding 8y agoOf course not to be confused with https://jasonette.com/ https://jasonette.com/ Naming things is the hardest thing... :)
- ckluis 8y agojasonette has always seemed like something that could be amazing
- nv-vn 8y agoThought so too until I tried it. Once you get started with it, it quickly becomes clear that it's all built on top of hacks that won't scale past a 1 page app. It's not a bad choice for prototyping, but I'm not convinced that it's any easier than prototyping with a real framework like Flutter.
- ropeadopepope 8y agoToo many {} and "" for rapid prototyping for me. I've always considered forking it to use yaml instead.
- mnr 8y agoRight? One time my boss asked me to do something in JSON but I explained to him I simply couldn’t work with JSON because of the braces and quotes. JSON is practically unusable.
- heavenlyhash 8y agoGood lord, wait until someone shows you computers. All the ones and zeros. A real mess we all can agree.
- murukesh_s 8y agoFor me (I believe few others) the {} and "" are ok as they provide a clear and consistent separation of structure and type at a quick glance, but the comma? That should have been avoided as even in JavaScript semicolons are increasingly being abandoned..
- chrisweekly 8y ago> "even in JavaScript semicolons are increasingly being abandoned" 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.
- DonHopkins 8y agoHere's a question I've been trying to answer: 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-with-spreadsheets-8f8832db5239 https://medium.com/@donhopkins/representing-and-editing-json... https://news.ycombinator.com/item?id=17309132 https://news.ycombinator.com/item?id=17309132 https://news.ycombinator.com/item?id=17360071 https://news.ycombinator.com/item?id=17360071 https://news.ycombinator.com/item?id=17360799 https://news.ycombinator.com/item?id=17360799 https://news.ycombinator.com/item?id=17360883 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/1nh8tlnanRaTmY8amABggxc0emaXCukCYR18EGddiC4w/edit 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/Assets/StreamingAssets/sheet.js 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://genshi.edgewall.org/ https://genshi.edgewall.org/
- chrisweekly 8y agoCool! This should be a top-level "Show HN" post.
- tylorr 8y agoAnd then there is Json.NET https://www.newtonsoft.com/json https://www.newtonsoft.com/json
- DonHopkins 8y agoReminds me of Marimba's product Castanet (which went with Bongo). Named by the same genius who came up with the name "Java" -- Kim Polese. https://www.wired.com/1996/11/es-marimba/ 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/front.html http://www.suck.com/netmoguls/96/10/18/back.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!"
- wellpast 8y agoI would love to see a complex, multi-file CloudFormation config expressed in jsonnet.
- andreabedini 8y agoThat’s exactly what we are using jsonnet for at my company. Introducing jsonnet in our CloudFormation work has given great results with almost zero up front cost (compare with other CloudFormation DSLs). This reminds me I should finish writing that blog post about it :)
- sytse 8y agoThis is the basis for Ksonnet, a Kubernetes helm chart replacement.
- sametmax 8y agoWhat's the benefit over a regular templating language ? Can't you do all that with jinja2 ?
- bryanlarsen 8y agoManipulating structured data using a text templating language is best left to masochists. For example, merging two objects is trivial in jsonnet yet pretty close to impossible in jinja2.
- blattimwind 8y ago+1, not everything is meant to go through the 11th iteration of the regex-meatgrinder.
- epage 8y agoAnother +1. I was recently contemplating a problem that could be aided by what I was calling strucural templating and almost wrote something like this.
- emidln 8y agoThe following would be trivial to build 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. }}
- bryanlarsen 8y agoSure, if you render the entire JSON in a single pipeline you can do a merge. But then you only have a single pipeline. 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.
- sametmax 8y ago
- ris 8y agoThey seem to be on the verge of inventing lisp.
- ttoinou 8y agoAnd it has comments !
- kuroikyu 8y ago> JSON + Variables, Conditionals, Arithmetic, Functions, Imports, Error Propagation Is this going full circle then? JS -> JSON -> JS. More seriously and like someone already said, to many brackets and quotes for rapid prototyping.
- penagwin 8y agoYes I am confused by this as well. It's a templating language for javascript objects? Isn't javascript a framework/language to create javascript objects? Other then interface with a few APIs (in browser or node.js) it can't do anything else.
- lttlrck 8y agoIf you’re using Javascript or have an embedded JavaScript runtime sure use that. 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.
- blacksoil 8y agoI think the use cases are more to generate JSON file, for example, to generate config file based on a template.
- wryun 8y agoI'm a fan of JSON-e over jsonnet (less complexity/safe with untrusted data, native libraries for Python/JS/Go instead of C++, + valid JSON/YAML on its own): https://taskcluster.github.io/json-e/ https://taskcluster.github.io/json-e/
- epage 8y agoThis is looking a little closer to what I was looking for.
- lihaoyi 8y agoWe just published a simple IntelliJ-Jsonnet integration, in case anyone else happens to also use those combinations of tools and is frustrated by lack of editor support https://plugins.jetbrains.com/plugin/10852-jsonnet https://plugins.jetbrains.com/plugin/10852-jsonnet Gives you syntax highlighting and basic jump-2-definition, though more advanced features are TODO.
- jurassic 8y agoI’m disappointed jsonnet is not a poem.
- kasajian 8y agoJust like any JSON is legal JavaScript, I want a functional programming language where any legal Jsonnet is a legal subset of the language. That'd be cool.
- jwdunne 8y agoI'm not sure but perhaps ReasonML is worth a look at? I don't know if you can specify property names with quotes. Lists are also homogenous but that'd be the case with most functional languages with a static type system. You could also go to town with reader macros in Lisp or use Racket.
- acjohnson55 8y agoJSON is not actually strictly a subset of JavaScript, surprisingly. Although, in practice, it doesn't really matter, because you wouldn't want to blindly eval JSON data, anyway. 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. http://timelessrepo.com/json-isnt-a-javascript-subset http://timelessrepo.com/json-isnt-a-javascript-subset
- Rygu 8y agoI'd prefer to use .js for configs.
- jackfraser 8y agoThis is why other people are suggesting that this is close to a reimplementation of Lisp - what you want by using a .js for your config is the right to use any kind of dynamic definition that suits your needs down the line, and have the application consume that config through some standard function call(s). When lists are code are lists, it's easy to make anything infinitely dynamic.
- xellisx 8y agoWanna get crazy, here's a PHP .INI configuration system. =) https://github.com/ellisgl/GeekLab-INIConf https://github.com/ellisgl/GeekLab-INIConf
- junke 8y ago{ person: self.person, } RUNTIME ERROR: max stack frames exceeded. { "self": "a", b: self.self } STATIC ERROR, expected token identifier but got self Looks good.
- rmetzler 8y agoCan somebody please explain what the difference is to jq and similar tools?
- nikolay 8y agoJsonnet is not new, but it's a missed opportunity as it's a big departure from the JavaScript semantics. It's Standard Library and syntax are unique, which is not a good thing for its purpose. It needs to be a subset of JavaScript, which could later become part of ECMAScript. I understand that its lazy evaluation nature required some of those, but still, I find it often to be much more pain than it should be!
- dagss 8y agoI don't understand that argument at all. Jsonnet generates JSON. Why does it itself need to be in JSON? 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.
- frumiousirc 8y agoI find Jsonnet incredibly useful to generate JSON while following a structured "don't repeat yourself" paradigm. It's a very good basis for a software application configuration system. It enables me to define a JSON schema which is most suitable for consumption by software while not forcing humans to slog through that in order to author the configuration. Adding some function and structure tooling in a little Jsonnet library helps humans write very expressive documents that can be compiled down to the repetitive and exhaustive JSON level.
- ksmith14 8y agoThis is exactly where I've found it can be helpful as well. 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. [1] https://github.com/benley/aurora-jsonnet https://github.com/benley/aurora-jsonnet