Jsonnet - The Data Templating Language
Description: The Jsonnet language allows elegant and easy description of JSON data.
Keywords: Jsonnet, JSON, YAML, language, configuration, configuration language, functional, declarative, lazy, structured, elegant, semantics, clean, mixins, inheritance, template, expansion, expand

The data templating language
Jsonnet

1. User docs
   Tutorial Demo Standard Library
2. Case Studies
   Fractal
3. Language
   Design Comparisons Specification
4. Implementation
   Cmdline Tool Libraries C++ Internals Javascript Tests
5. Contributing

# Libraries For Other Languages

If you don't want to invoke the jsonnet commandline utility to evaluate Jsonnet, there are also libraries for Python and C. In future we would like to support more languages by wrapping the C API in each case.

## C API

The C API simply wraps the C++ implementation to hide C++ language features like templates, classes, overloading, etc. This makes it easier to bind to other languages, as C is typically the lowest common denominator across all systems.

The API is documented in libjsonnet.h. It is built with 'make libjsonnet.so'. It is used by the python bindings, the Jsonnet commandline tool, as well as a couple of simpler tests. Search for #include "libjsonnet.h".

To use the API, create a JsonnetVM object, set various options, then tell it to evaluate a filename or snippet. To avoid leaking memory, the result of execution (JSON or error message) and the JsonnetVM object itself must be cleaned up using the corresponding functions.

## Python API

The Python API wraps the C API in a straightforward way. It can be built with 'make _libjsonnet.so'. The Python module provides two functions, `evaluate_file(f)` and `evaluate_snippet(f, e)`. In the latter case, the parameter `f` is used in stack traces due to errors raised in the snippet.

Keyword arguments to these functions are used to control the virtual machine. They are `gc_min_objects`, `gc_growth_trigger`, `env`, `debug_ast`, and `max_trace`. The `debug_ast` argument is a boolean, and `env` is a dict mapping strings to strings. The other keyword arguments should be numbers.

If an error is raised during the evaluation of the Jsonnet code, it is formed into a stack trace and thrown as a python RuntimeError. Otherwise, the JSON string is returned. To convert this into objects for easy interpretation in Python, use the json module.

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