3

Jsonnet - The Data Templating Language

 1 year ago
source link: https://jsonnet.org/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

The Data Templating Language

Loading [MathJax]/extensions/MathMenu.js
isologo.svg

A data templating language
for app and tool developers

  • Generate config data
  • Side-effect free
  • Organize, simplify, unify
  • Manage sprawling config

A simple extension of JSON

  • Open source (Apache 2.0)
  • Familiar syntax
  • Reformatter, linter
  • Editor & IDE integrations
  • Formally specified
venn.svg

Eliminate duplication with object-orientation:

// Edit me!
{
  person1: {
    name: "Alice",
    welcome: "Hello " + self.name + "!",
  },
  person2: self.person1 { name: "Bob" },
}

Or, use functions:

// A function that returns an object.
local Person(name='Alice') = {
  name: name,
  welcome: 'Hello ' + name + '!',
};
{
  person1: Person(),
  person2: Person('Bob'),
}

Integrate with existing / custom applications.
Generate JSON, YAML, INI, and other formats.

local application = 'my-app';
local module = 'uwsgi_module';
local dir = '/var/www';
local permission = 644;
{
  'uwsgi.ini': std.manifestIni({
    sections: {
      uwsgi: {
        module: module,
        pythonpath: dir,
        socket: dir + '/uwsgi.sock',
        'chmod-socket': permission,
        callable: application,
        logto: '/var/log/uwsgi/uwsgi.log',
      },
    },
  }),
  'init.sh': |||
    #!/usr/bin/env bash
    mkdir -p %(dir)s
    touch %(dir)s/initialized
    chmod %(perm)d %(dir)s/initialized
  ||| % {dir: dir, perm: permission},
  'cassandra.conf': std.manifestYamlDoc({
    cluster_name: application,
    seed_provider: [
      {
        class_name: 'SimpleSeedProvider',
        parameters: [{ seeds: '127.0.0.1' }],
      },
    ],
  }),
}

The name Jsonnet is a portmanteau of JSON and sonnet, pronounced "jay sonnet". It began life early 2014 as a 20% project and was launched on Aug 6. The design is influenced by several configuration languages internal to Google, and embodies years of experience configuring some of the world's most complex IT systems. Jsonnet is now used by many companies and projects. Jsonnet is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.

deepmind.png grafana.svg

Except as noted, this content is licensed under Creative Commons Attribution 2.5.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK