tjson-rs
A Rust library and CLI tool for TJSON
TJSON is a hyper-readable, round trip safe and data preserving substitute for JSON that feels like text and represents the same data while looking quite different and allowing different generator rules to optimize readibility. It is not a superset or a subset of JSON. It's commonality is that it represents the same underlying data, not the format itself. It's position based to emphasize locality of meaning, and adds bare strings, pipe tables, comments, multiline string literals, and line folding to make the contained data easier to read while remaining fully convertible to and from standard JSON without data loss. TJSON is optimized for reading and deterministic data, not human editing.
Usage as a binary, library (including WASM too), and through serde Serialize are all fully supported.
Installation
Add to your Cargo.toml:
[]
= "0.1"
Install the CLI:
Library Usage
Parse TJSON
use TjsonValue;
// Parse a TJSON object (keys indented 2 spaces at the top level)
let value: TjsonValue = " name: Alice\n age:30".parse?;
// Parse a bare string
let value: TjsonValue = " hello world".parse?;
Render to TJSON
use ;
let value = from;
// Default options
let tjson = value.to_tjson_with?;
// Canonical (one key per line, no packing)
let canonical = value.to_tjson_with?;
Serde integration
use ;
// Deserialize from TJSON
let person: Person = from_str?;
// Serialize to TJSON
let tjson = to_string?;
CLI Usage
# JSON to TJSON
|
# TJSON to JSON
|
# From/to files
# Canonical output
WASM / JavaScript
The library compiles to WebAssembly via wasm-pack:
Resources
- Website and online demo: textjson.com
- Specification: tjson-specification.md
- Test suite: tjson-tests
License
BSD-3-Clause. See LICENSE.