Skip to content

tron-format/tron-javascript

Repository files navigation

@tron-format/tron

CI License: MIT

A JavaScript library for converting data to and from the TRON (Token Reduced Object Notation) format.

See full specification for the TRON format at: https://tron-format.github.io/

Installation

npm i @tron-format/tron

Usage

import { TRON } from '@tron-format/tron';

const value = [{ a: 1, b: 2 }, { a: 3, b: 4 }];
const tron = TRON.stringify(value);
console.log(tron);
// Output: 
// class A: a,b
// 
// [A(1,2), A(3,4)]

const parsed = TRON.parse(tron);
console.log(parsed);
// Output:
// [{ a: 1, b: 2 }, { a: 3, b: 4 }]

Considerations

Using stringify with undefined

In JavaScript, calling JSON.stringify(undefined) returns undefined. However, calling TRON.stringify(undefined) returns 'null' instead. This is intentional to better align with the function's return type (string only) for TypeScript.

Other cases of stringifying undefined are handled the same way as JSON.stringify. For example:

  • TRON.stringify([undefined]) returns '[null]' (same behavior as JSON.stringify([undefined]))
  • TRON.stringify({ a: undefined }) returns '{}' (same behavior as JSON.stringify({ a: undefined }))

Playground

Want to try out TRON with your own JSON data?

Go to https://tron-format.github.io/#/playground and select "Custom Data".

Paste in your data to see TRON's token efficiency compared to other data formats!

License

MIT License © 2025-PRESENT Tim Huang

About

A JavaScript library for working with the TRON format

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors