A compact, URL-friendly serialization format that is smaller than JSON while remaining human-readable and fast to parse.
RJSON (Remote JavaScript Object Notation) is a specification and implementation inspired by RISON and it is designed for:
- Better frontend-to-backend communication via search parameters.
- Compact payloads
- Human-readable configuration
- Fast parsing without AST generation
- JavaScript-native data structures
- β‘ Fast parser with direct character scanning (recursive descent parsing).
- π¦ Smaller than JSON for many real-world payloads
- π URL-friendly syntax
- π§© Supports objects, arrays, strings, numbers, booleans
- π Supports
nullandundefined - ποΈ Built-in mapped-array compression
- π Tagged template support
- π§ Zero dependencies
- π¦ TypeScript ready
- π Runtime agnostic (Node.js, Bun, Deno)
- Features
- Installation
- Quick Start
- Syntax Overview
- Core Types
- Mapped Arrays
- API Reference
- Design Goals
- License
bun add @bepalo/rjsonnpm install @bepalo/rjsonpnpm add @bepalo/rjsonimport { RJSON } from "jsr:@bepalo/rjson";import { RJSON } from "@bepalo/rjson";
const user = RJSON.parse("(name:'Natnael',age:25,active:T)");
console.log(user);Output:
{
name: "Natnael",
age: 25,
active: true
}import { RJSON } from "@bepalo/rjson";
const text = RJSON.stringify({
name: "Natnael",
age: 25,
active: true,
});
console.log(text);Output:
(name:'Natnael',age:25,active:T)import { RJSON } from "@bepalo/rjson";
const text = RJSON.stringify([1, 3.1415, null, undefined, true, "hello"]);
console.log(text);Output:
_(1,3.1415,,U,T,'hello')_import { RJSON } from "@bepalo/rjson";
const text = RJSON.stringifyMappedArray(true, ["id", "title", "body"]);
console.log(text);Output:
~T(id,title,body)~import { rjson } from "@bepalo/rjson";
const user = rjson`(name:'Natnael',age:25,active:T)`;
console.log(user);Output:
{
name: "Natnael",
age: 25,
active: true,
}| Type | RJSON | JSON |
|---|---|---|
| Object | (name:'John') |
{"name":"John"} |
| Array | _(1,2,3)_ |
[1,2,3] |
| String | 'hello' "hello" `hello` |
"hello" |
| Number | 123 |
123 |
| Boolean | T / F |
true / false |
| Null | N |
null |
| Undefined | U |
Not supported |
| Mapped Array | ~T(admin,user)~ |
{"admin":true,"user":true} |
(name:'John',age:30)Produces:
{
name: "John",
age: 30
}_(1,2,3,4)_Produces:
[1, 2, 3, 4];(user:(name:'John',age:30),active:T)Produces:
{
user: {
name: "John",
age: 30
},
active: true
}Supported delimiters:
'hello'
"hello"
`hello`Escaping:
'can\'t'const text = `'can\\'t'`;Produces:
"can't";Supported formats:
123
-123
+123
12.5
1e10
1e-10Examples:
age:25
price:19.99
distance:1.5e6TProduces:
true;FProduces:
false;NProduces:
null;Empty values are also treated as null:
(name:)Produces:
{
name: null;
}(name:U)Produces:
{
name: undefined;
}Mapped arrays compress repeated values.
Instead of:
{
admin: true,
editor: true,
user: true
}Use:
~T(admin,editor,user)~Result:
{
admin: true,
editor: true,
user: true
}The value can be any valid RJSON type
~F(create,update,delete)~
~(roles:_('admin','user')_)(create,update,delete)~
~~F(admin,user)~(create,update,delete)~Parses RJSON text.
const value = parseRJSON("(name:'John',active:T)");Serializes JavaScript values.
const text = stringifyRJSON({
name: "John",
active: true,
});Result:
(name:'John',active:T)Creates mapped-array expressions.
stringifyRJSONMappedArray(true, ["read", "write", "delete"]);Result:
~T(read,write,delete)~Tagged-template parser.
const data = rjson`
(name:'John')
`;It is designed for better frontend-to-backend communication via search parameters.
Benefits:
- Smaller payloads
- Easier URL embedding
- Human-readable
- JavaScript-oriented
- Fast parsing
Example:
JSON
{
"name": "John",
"active": true,
"roles": ["admin", "user"]
}RJSON
(name:'John',active:T,roles:_('admin','user')_)- Whitespace is forbidden.
- Designed primarily for compact transport and URLs.
Invalid:
(
name : 'John'
)Valid:
(name:'John')MIT
If you find RJSON useful, please consider starring the repository and sharing it with others.
Support development and future improvements.
