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 readability. It is not a superset or a subset of JSON, but it does represent the same underlying data in a different format. 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 while retaining exactly the same data. 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:
[]
= { = "tjson-rs", = "0.4" }
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, see docs for details)
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
Install:
Usage:
import from '@rfanth/tjson';
// Render JSON as TJSON with or without options
const tjsonString = ;
const tjsonStringNarrow = ;
// Parse TJSON to a JSON string
const jsonString = ;
// Render from a native javascript object with or without options (camelCase for WASM/JS only)
const defaultTjson = ;
const canonicalTjson = ;
const noFoldTjson = ;
// Parse TJSON to a native javascript value
const jsObject = ;
Resources
- Website and online demo: textjson.com
- Specification: tjson-specification.md
- Test suite: tjson-tests
License
BSD-3-Clause. See LICENSE.