Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Jsonnet

132 views

Published on

Ignite talk for Config Management Camp

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Jsonnet

  1. 1. Jsonnet Julien Pivotto (@roidelapluie) Config Management Camp Ghent February 2018
  2. 2. YAML Creative Commons Attribution 2.0 https://www.flickr.com/photos/calliope/234447967
  3. 3. JSON Creative Commons Attribution 2.0 https://www.flickr.com/photos/xewboy/7656416920
  4. 4. JSON = subset of YAML Creative Commons Attribution 2.0 https://www.flickr.com/photos/withgeorge/6661248205/
  5. 5. All JSON Engineers are YAML Engineers All YAML Engineers are not JSON Engineers Pick your side :)
  6. 6. Jsonnet DSL to build JSON data. Json on steroids.
  7. 7. Subsets Supersets YAML is a superset of JSON Jsonnet is a supetset of Jsonnet Every JSON is valid Jsonnet Every JSON is valid YAML Jsonnet compiles to JSON Jsonnet compiled is YAML compliant ... Understood????
  8. 8. Jsonnet http://jsonnet.org/ https://github.com/google/jsonnet Open Source C++
  9. 9. Jsonnet, input // Jsonnet Example {     person1: {         name: "Alice",         welcome: "Hello " + self.name + "!",     },     person2: self.person1 { name: "Bob" }, } http://jsonnet.org/
  10. 10. Jsonnet, output {    "person1": {       "name": "Alice",       "welcome": "Hello Alice!"    },    "person2": {       "name": "Bob",       "welcome": "Hello Bob!"    } } http://jsonnet.org/
  11. 11. Comments Comments do not exist in JSON. In Jsonnet: // This. /* And this. */
  12. 12. Rules for Humans In JSON, commas are not allowed at the end of arrays In Jsonnet: [ 'commas', 'are', 'allowed',   'at', 'the', 'end', 'of', 'arrays', ]
  13. 13. Simplicity Json: {"foo": "bar"} Jsonnet: {foo: "bar"}
  14. 14. Variables local tool_name = "puppet"; local modules_total = 10; {     tool: tool_name,     modules: modules_total,  }
  15. 15. Functions {   new(name, kind):: {     oname: name,     kind: kind,     max: 10   },   foo: $.new("foo", "bar") }
  16. 16. Imports local grafana = import "grafana.libsonnet"; local dashboard = grafana.dashboard; dashboard.new(     "Device USE by slot",     tags=["Technical", "Overview"], )
  17. 17. stdlib Strings join Replace Maps Inserts Loops ...
  18. 18. Usage jsonnet  foo.jsonnet > foo.json Multi files: jsonnet ­m dashboards dashboards.jsonnet Style: jsonnet fmt
  19. 19. Real life examples jsonnet grafonnet ... Try it Bindinfs for several languages Available for vim, vscode, atom
  20. 20. My use case Generating grafana dashboards Reuse panels between graphs Reuse links Force same colors between graphes Reduce maintainance costs of graphes github.com/grafana/grafonnet-lib

×