# 2.3 Compiling JSONAir

JSONAir uses a standard Go toolchain and a `Makefile` for convenience. The end result is three standalone static binaries — the server, the agent, and the encryption utility.

***

## Before You Start

Make sure you have:

* Go 1.26.2 or later installed (`go version` to confirm)
* The repository cloned locally:

```bash
git clone https://github.com/k9io/jsonair.git
cd jsonair
```

***

## Building with Make (Recommended)

The simplest way to build everything is to run `make` from the repository root. This will tidy the Go module dependencies and compile both binaries in one step.

```bash
make
```

This is equivalent to running:

```bash
make tidy
make build
```

The compiled binaries are placed in the `bin/` directory:

```
bin/
  jsonair/jsonair                        ← the JSONAir server
  jsonair-agent/jsonair-agent            ← the JSONAir agent
  jsonair-encrypt/jsonair-encrypt        ← the config data encryption tool
```

***

## Building Individual Components

If you only need one of the binaries, you can build them separately.

**Server only:**

```bash
make jsonair
```

**Agent only:**

```bash
make jsonair-agent
```

**Encryption tool only:**

```bash
make jsonair-encrypt
```

***

## Building Directly with Go

You can also build without `make` using the Go toolchain directly.

**Server:**

```bash
go build -o bin/jsonair/jsonair ./cmd/jsonair
```

**Agent:**

```bash
go build -o bin/jsonair-agent/jsonair-agent ./cmd/jsonair-agent
```

**Encryption tool:**

```bash
go build -o bin/jsonair-encrypt/jsonair-encrypt ./cmd/jsonair-encrypt
```

***

## Running the Tests

```bash
go test ./...
```

***

## Cleaning Build Artifacts

To remove the `bin/` directory and start fresh:

```bash
make clean
```

***

## Cross-Compilation

Because JSONAir has no C dependencies, it cross-compiles cleanly using Go's built-in support. Set `GOOS` and `GOARCH` before the build command to target a different platform.

**Example — build the server for Linux (amd64) on a Mac:**

```bash
GOOS=linux GOARCH=amd64 go build -o bin/jsonair/jsonair ./cmd/jsonair
```

**Common targets:**

| Platform                        | GOOS     | GOARCH  |
| ------------------------------- | -------- | ------- |
| Linux 64-bit                    | `linux`  | `amd64` |
| Linux ARM64 (e.g. AWS Graviton) | `linux`  | `arm64` |
| macOS Intel                     | `darwin` | `amd64` |
| macOS Apple Silicon             | `darwin` | `arm64` |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.k9.io/key9-identity/jsonair/2-install/2.3-compiling-jsonair.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
