Code Monkey home page Code Monkey logo

jsonnet's Introduction

Jsonnet - The data templating language

master branch build status badge

For an introduction to Jsonnet and documentation, visit our website.

This repository contains the original implementation. You can also try go-jsonnet, a newer implementation which in some cases is orders of magnitude faster.

Visit our discussion forum.

Packages

Jsonnet is available on Homebrew:

brew install jsonnet

Jsonnet is available on MSYS2:

pacman -S mingw-w64-clang-i686-jsonnet
pacman -S mingw-w64-clang-x86_64-jsonnet
pacman -S mingw-w64-i686-jsonnet
pacman -S mingw-w64-x86_64-jsonnet
pacman -S mingw-w64-ucrt-x86_64-jsonnet

The Python binding is on pypi:

pip install jsonnet

You can also download and install Jsonnet using the vcpkg dependency manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
vcpkg install jsonnet

The Jsonnet port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Building Jsonnet

You can use either GCC or Clang to build Jsonnet. Note that on recent versions of macOS, /usr/bin/gcc and /usr/bin/g++ are actually Clang, so there is no difference.

Makefile

To build Jsonnet with GCC, run:

make

To build Jsonnet with Clang, run:

make CC=clang CXX=clang++

To run the output binary, run:

./jsonnet

To run the reformatter, run:

./jsonnetfmt

Bazel

Bazel builds are also supported. Install Bazel if it is not installed already. Then, run the following command to build with GCC:

bazel build -c opt //cmd:all

To build with Clang, use one of these two options:

env CC=clang CXX=clang++ bazel build -c opt //cmd:all

# OR

bazel build -c opt --action_env=CC=clang --action_env=CXX=clang++ //cmd:all

This builds the jsonnet and jsonnetfmt targets defined in cmd/BUILD. To launch the output binaries, run:

bazel-bin/cmd/jsonnet
bazel-bin/cmd/jsonnetfmt

Cmake

cmake . -Bbuild
cmake --build build --target run_tests

Contributing

See the contributing page on our website.

Developing Jsonnet

Running tests

To run the comprehensive suite:

make test

Locally serving the website

You need a doc/js/libjsonnet.wasm which can either be downloaded from the production website:

wget https://jsonnet.org/js/libjsonnet.wasm -O doc/js/libjsonnet.wasm

Or you can build it yourself, which requires checking out go-jsonnet. See the README.md in that repo for instructions.

The standard library is documented in a structured format in doc/_stdlib_gen/stdlib-content.jsonnet. The HTML (input for Jekyll) is regenerated using the following command:

tools/scripts/update_web_content.sh

Then, from the root of the repository you can generate and serve the website using Jekyll (you need version 4.3.0 or later):

jekyll serve -s doc/

This should build and serve the website locally, and automatically rebuild when you change any underlying files.

jsonnet's People

Contributors

benley avatar camh- avatar cdluminate avatar davidzchen avatar deepgoel17 avatar dmuir-g avatar duologic avatar gburiola avatar hanazuki avatar hanyucui avatar johnbartholomew avatar ketchupbomb avatar loverszhaokai avatar mikedanese avatar mortenmj avatar oconnorr avatar osher avatar podsvirov avatar redbaron avatar refi64 avatar rhowe avatar rohitjangid avatar sbarzowski avatar scr-oath avatar sparkprime avatar spencels avatar tejesh-raut avatar timp87 avatar toge avatar yegle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsonnet's Issues

Arbitrary precision rational arithmetic

Using double precision floating point has its flaws, e.g. rounding errors. It makes sense to use arbitrary precision rational arithmetic in Jsonnet. We will have to find a library with a decent license that does not bloat the binary size too much, and then replace the current number representation.

Need to bound the memory use of Jsonnet evaluation

The interpreter currently knows how many objects are live, but not how large they are. If it had this extra information, it would be possible to place a bound on the amount of memory that can be used during execution. This makes it safer to run Jsonnet in a server environment.

Add a system for searching for libraries from a path.

Jsonnet would hardcode some paths

/usr/share/jsonnet
/usr/local/share/jsonnet

You would also be able to add additional search directories with a JSONNET_PATH environment variable.

Perhaps the hardcoded paths would have version numbers in them.

Need to trap and redirect the implementation of the import construct

There are contexts where allowing Jsonnet programs to access the file system is inappropriate, for example when a server executes code provided by a user. In those cases, it may still make sense for the import keyword to do something useful, but the service that is using the Jsonnet library needs to provide some sort of callback to handle the import construct in that case.

Jsonnet will still cache the result of the import to maintian referential transparency.

Need to bound execution time

It is currently possible to write programs that run for a long time, such as computing the Ackerman function. This is bad news if Jsonnet is integrated into a server, where such programs will use excess CPU resources and block other users.

Jsonnet should count the number of loops around the VM, and bound it either in number of instructions, or in time by calling the time syscall every 1000 instructions (or whatever).

Tail call optimization

The current implementations of foldl (and similar routines) rely on tail call recursion, but currently they blow the stack when operating on arrays that are too long. This can be fixed by optimizing tail calls to re-use their current stack frame.

I think an explicit construct for enabling the optimization is better than applying it for all tail calls, because then you preserve stack traces in the majority of cases where the optimization is not required.

More expressive comprehension syntax.

Currently, list comprehension only supports a single 'for' and a single 'if'. In Python, an unlimited number of these can be specified, and they can be interleaved arbitrarily. Consider extending Jsonnet to be equally expressive.

Make include guards unique

I find that include guards like "AST_H" and "VM_H" are too short for the safe reuse of your header files (when they belong to an application programming interface).

terminate called after throwing an instance of 'std::ios_base::failure'

$ ls folder
input.jsonnet
$ cat folder/input.jsonnet

import "" {
    cocktails +: {
        "Whiskey Sour": {
            ingredients: [
                { kind: "Scotch", qty: 1.5 },
                { kind: "Lemon Juice", qty: 0.75 },
            ],
            garnish: "Lemon Peel",
            served: "On The Rocks",
        }
    }
}

$ ../jsonnet folder/input.jsonnet
terminate called after throwing an instance of 'std::ios_base::failure'
what(): basic_filebuf::underflow error reading the file
Aborted

Support Unicode

Currently only ASCII is supported in strings. It should not be too hard to accept UTF-8 (raising an error for invalid input), and adjust internal string routines to support unparsing those strings correctly, as well as routines for iterating over codepoints, correctly determining the length (in codepoints), etc.

Add a date library

Code to convert to/from tuples like {year: x, month:x, ... seconds: x } into textual / other structured representations (seconds since epoch, etc).

Please support ES6 back-tick for strings

ES6 has some wonderful functionality based on strings wrapped in the back-tick (`) instead of the standard double-quote (") and single-quote (') characters.

Please, PLEASE add full support for the ES6 back-tick functionality!

Python 3.x Compatibility

I forked and converted to use Visual Studio, and I also changed support from Python 2 C API to Python 3.4 API. It wasn't horribly difficult to do either task, but the project is there for anybody who needs or wants it.

Importing from URLs

It may be useful to import from a URL, or otherwise contact an external service. The current semantics would be a special case of this, i.e. file://path.

It is not clear whether the request should be parameterizable.

Either way, Jsonnet will still cache the result of fetching the URL to enforce referential transparency.

Add # comment syntax

The behavior is the same as //

The purpose is to allow "hash bang" lines at the top of the file, and also be consistent with other syntaxes such as Python and YAML.

Import file as a string

It would be good to have an import_as_string construct that behaves similarly to import "foo.jsonnet" but instead yields the contents of a file as an uninterpreted string. This would be useful for embedding bash scripts, for example.

Add a REPL

For exploring Jsonnet, it would be nice to have a REPL, e.g., via jsonnet -i. For inspiration, I would look to Scala's REPL as an example.

Require unit test

I think it is better if there are unit tests, such as using gtest.

Cmdline flag to check two jsonnet files manifest equivalently

Evaluate both files and check JSON output is the same.

This is useful when refactoring to know whether or not the changes were purely internal (good) or had some external effect (bad).

E.g. if you're a vim user:

jsonnet --compare Foo.jsonnet Foo.jsonnet~

Can output a diff of the two JSON strings.

Conflicts with --multi.

test/error.import_folder.jsonnet has different output depending on OS

Runtime platform OSX 10.10.3:

# ../jsonnet --gc-min-objects 1 --gc-growth-trigger 1 error.import_folder.jsonnet
STATIC ERROR: lib:1:1: Unexpected end of file.

this error is different from the linux runtime error, https://github.com/google/jsonnet/blob/master/test_suite/error.import_empty.jsonnet.golden
so the test fails.

Suggested fix to work on multiple OS platforms might be to insert platform name (eg error.import_folder.jsonnet.darwin.golden) and test for existence of a platform-specific file within run_tests.sh.

Optional fields

It would be good if a computed field name evaluated to null, rather than being a dynamic error, if that field was simply omitted from the object. For example

{
    x: 1,
    [if nighttime then "light_brightness" else null]: 100,
}

Will yield either {x: 1} or {x: 1, light_brightness: 100} depending on whether nighttime is true.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.