#jsonnet #api-bindings #string #start #go-jsonnet #jsonnet-vm

jsonnet-go

Idiomatic rust bindings for go-jsonnet

1 unstable release

0.1.0 Sep 22, 2024

#779 in Configuration

Download history 101/week @ 2024-12-14 55/week @ 2024-12-21 232/week @ 2024-12-28 84/week @ 2025-01-04 177/week @ 2025-01-11 65/week @ 2025-01-18 64/week @ 2025-01-25 117/week @ 2025-02-01 372/week @ 2025-02-08 62/week @ 2025-02-15 149/week @ 2025-02-22 158/week @ 2025-03-01 169/week @ 2025-03-08 201/week @ 2025-03-15 99/week @ 2025-03-22 95/week @ 2025-03-29

569 downloads per month

MIT/Apache

80KB
1.5K SLoC

jsonnet-go

Run jsonnet programs in rust!

This crate provides idiomatic Rust bindings for the go-jsonnet library.

Quick Start

Create a JsonnetVm and then call evaluate_file or evaluate_snippet to run jsonnet code. These will return a string containing the resulting JSON:

use jsonnet_go::JsonnetVm;

fn main() -> jsonnet_go::Result<()> {
    let mut vm = JsonnetVm::new();
    let jsonnet = "{ field: std.base64('Hello, World!') }";
    let json = vm.evaluate_snippet("<inline>", jsonnet)?;

    println!("{json}");
    Ok(())
}

Alternatively, you could enable the json feature and use evaluate_json to deserialize the returned JSON string:

use jsonnet_go::{JsonnetVm, EvaluateOptions};
use serde::Deserialize;

#[derive(Deserialize)]
struct Output {
    field: String
}

fn main() -> jsonnet_go::Result<()> {
    let mut vm = JsonnetVm::new();
    let jsonnet = "{ field: std.base64('Hello, World!') }";
    let options = EvaluateOptions::new("<inline>").snippet(jsonnet);
    let output: Output = vm.evaluate_json(options)?;

    assert_eq!(output.field, "SGVsbG8sIFdvcmxkIQ==");

    Ok(())
}

Build Dependencies

You will need go 1.12+ installed in order to build go-jsonnet. You can install it via:

On older distros the packaged version of go may not be new enough. In that case you will need to install it from the official website.

See Also

  • The jsonnet-rs is a similar set of bindings for the libjsonnet C++ library. However, it has not been updated since jsonnet 0.17 and optimizations now mainly added to go-jsonnet and not libjsonnet.

Dependencies

~12MB
~321K SLoC