An open API service indexing awesome lists of open source software.

https://github.com/danielkov/toon-rust

Serde-compatible serializer and deserializer for TOON (Token-Oriented Object Notation)
https://github.com/danielkov/toon-rust

Last synced: 8 days ago
JSON representation

Serde-compatible serializer and deserializer for TOON (Token-Oriented Object Notation)

Awesome Lists containing this project

README

          

# toon

Command-line tool for converting between JSON/YAML and TOON (Token-Oriented Object Notation) formats.

## Installation

```sh
cargo install --git https://github.com/danielkov/toon-rust
```

## Usage

The CLI provides two subcommands: `encode` (JSON/YAML → TOON) and `decode` (TOON → JSON/YAML).

### Encode JSON/YAML to TOON

```sh
toon encode [OPTIONS]
toon e [OPTIONS] # short alias
```

**Options:**

- `--delimiter ` - Array element delimiter (default: comma)
- `--indent ` - Spaces per indentation level (default: 2)
- `--key-folding ` - Key folding mode (default: off)
- `--flatten-depth ` - Maximum depth for inlining nested structures

**Examples:**

```sh
# Convert JSON file to TOON
toon encode data.json

# Convert YAML file to TOON
toon encode data.yaml

# Fetch and convert JSON from URL
toon encode https://api.github.com/users

# Convert inline JSON string
toon e '{"name":"Alice","age":30}'

# Use pipe delimiter for arrays
toon encode --delimiter pipe data.json
```

### Decode TOON to JSON/YAML

```sh
toon decode [OPTIONS]
toon d [OPTIONS] # short alias
```

**Options:**

- `--indent ` - Spaces per indentation level (default: 2)
- `--strict` - Enable strict validation mode
- `--expand-paths ` - Path expansion mode (default: off)
- `-o, --output-type ` - Output format (default: json)

**Examples:**

```sh
# Convert TOON file to JSON
toon decode data.toon

# Convert TOON to YAML
toon decode --output-type yaml data.toon
toon d -o yaml data.toon

# Convert inline TOON string
toon d 'name Alice age 30'

# Enable strict validation
toon decode --strict data.toon
```

## Input Sources

The tool accepts three types of input:

- **File paths** - Reads from local filesystem
- **URLs** - Fetches content via HTTP/HTTPS GET request
- **Raw strings** - Parses string directly from command line argument

## Output

All output is written to stdout. Pipe to a file or other tools as needed:

```sh
toon encode data.json > output.toon
toon decode data.toon | jq .
```