README.md

<!--START-->
<p align="center">
  <img align="center" width="50%" src="guides/images/logo.png" alt="Jsonnex Logo">
</p>

<p align="center">
  An Elixir wrapper for the <a href="https://github.com/google/go-jsonnet">Golang Jsonnet</a> compiler.
</p>

<p align="center">
  <a href="https://hex.pm/packages/jsonnex">
    <img alt="Hex.pm" src="https://img.shields.io/hexpm/v/jsonnex?style=for-the-badge">
  </a>

  <a href="https://github.com/akoutmos/jsonnex/actions">
    <img alt="GitHub Workflow Status (master)"
    src="https://img.shields.io/github/actions/workflow/status/akoutmos/jsonnex/main.yml?label=Build%20Status&style=for-the-badge&branch=master">
  </a>

  <a href="https://coveralls.io/github/akoutmos/jsonnex?branch=master">
    <img alt="Coveralls master branch" src="https://img.shields.io/coveralls/github/akoutmos/jsonnex/master?style=for-the-badge">
  </a>

  <a href="https://github.com/sponsors/akoutmos">
    <img alt="Support Jsonnex" src="https://img.shields.io/badge/Support%20Jsonnex-%E2%9D%A4-lightblue?style=for-the-badge">
  </a>
</p>

<br>
<!--END-->

# Contents

- [Introduction](#introduction)
- [Installation](#installation)
- [Quick Start](#quick-start)

## Introduction

Jsonnet is a configuration language that compiles to JSON. While JSON only has support for arrays, objects and
primitives, Jsonnet has support for those as well as variables, conditionals, arithmetic, functions, imports and error
propagation.

For example, the following Jsonnet code:

```jsonnet
{
  person1: {
    name: "Alice",
    welcome: "Hello " + self.name + "!",
  },
  person2: self.person1 { name: "Bob" },
}
```

Would compile to the following JSON:

```json
{
  "person1": {
    "name": "Alice",
    "welcome": "Hello Alice!"
  },
  "person2": {
    "name": "Bob",
    "welcome": "Hello Bob!"
  }
}
```

For more information and examples about the Jsonnet language, be sure to check out the
[official documentation](https://jsonnet.org/).

## Installation

Add `Jsonnex` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:jsonnex, "~> 0.1.0"}
  ]
end
```

## Quick Start

After you have installed the `:jsonnex` dependency, you can use the library in your application as follows to compile
Jsonnet code:

```elixir
{:ok, %{"person1" => _, "person2" => _}} =
  Jsonnex.compile(~S[
  // A function that returns an object.
  local Person(name='Alice') = {
    name: name,
    welcome: 'Hello ' + name + '!',
  };
  {
    person1: Person(),
    person2: Person('Bob'),
  }])
```

If you would like to embed and format Jsonnet code in your application, you can use the `~JSONNET` sigil and add the
following to your `.formater.exs` file:

```elixir
# Used by "mix format"
[
  inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
  plugins: [Jsonnex.MixFormatter],
  jsonnet: [ # For supported options look at the `Jsonnex.Format` module
    string_style: :single
  ]
]
```