Universal serialization library to encode/decode objects to/from Links Notation format. Available in both Python and JavaScript with identical functionality and API design.
This library provides universal serialization and deserialization with built-in support for circular references and complex object graphs in:
- Python - Full implementation for Python 3.8+
- JavaScript - Full implementation for Node.js 18+
Both implementations share the same design philosophy and provide feature parity.
- Universal Serialization: Encode objects to Links Notation format
- Type Support: Handle all common types in each language:
- Python:
None,bool,int,float,str,list,dict - JavaScript:
null,undefined,boolean,number,string,Array,Object - Special float/number values:
NaN,Infinity,-Infinity
- Python:
- Circular References: Automatically detect and preserve circular references
- Object Identity: Maintain object identity for shared references
- UTF-8 Support: Full Unicode string support using base64 encoding
- Simple API: Easy-to-use
encode()anddecode()functions
pip install link-notation-objects-codecfrom link_notation_objects_codec import encode, decode
# Encode and decode
data = {"name": "Alice", "age": 30, "active": True}
encoded = encode(data)
decoded = decode(encoded)
assert decoded == datanpm install link-notation-objects-codecimport { encode, decode } from 'link-notation-objects-codec';
// Encode and decode
const data = { name: 'Alice', age: 30, active: true };
const encoded = encode(data);
const decoded = decode(encoded);
console.log(JSON.stringify(decoded) === JSON.stringify(data)); // true.
βββ python/ # Python implementation
β βββ src/ # Source code
β βββ tests/ # Test suite
β βββ examples/ # Usage examples
β βββ README.md # Python-specific docs
βββ js/ # JavaScript implementation
β βββ src/ # Source code
β βββ tests/ # Test suite
β βββ examples/ # Usage examples
β βββ README.md # JavaScript-specific docs
βββ README.md # This file
For detailed documentation, API reference, and examples, see:
Both implementations support the same features with language-appropriate syntax:
Python:
from link_notation_objects_codec import encode, decode
# Self-referencing list
lst = [1, 2, 3]
lst.append(lst)
decoded = decode(encode(lst))
assert decoded[3] is decoded # Reference preservedJavaScript:
import { encode, decode } from 'link-notation-objects-codec';
// Self-referencing array
const arr = [1, 2, 3];
arr.push(arr);
const decoded = decode(encode(arr));
console.log(decoded[3] === decoded); // true - Reference preservedPython:
data = {
"users": [
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"}
],
"metadata": {"version": 1, "count": 2}
}
assert decode(encode(data)) == dataJavaScript:
const data = {
users: [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' }
],
metadata: { version: 1, count: 2 }
};
console.log(JSON.stringify(decode(encode(data))) === JSON.stringify(data));The library uses the links-notation format as the serialization target. Each object is encoded as a Link with type information:
- Basic types are encoded with type markers:
(int 42),(str "hello"),(bool True) - Strings are base64-encoded to handle special characters and newlines
- Collections include object IDs for reference tracking:
(list obj_0 item1 item2 ...) - Circular references use special
reflinks:(ref obj_0)
This approach allows for:
- Universal representation of object graphs
- Preservation of object identity
- Natural handling of circular references
- Cross-language compatibility
cd python
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest tests/ -vcd js
npm install
npm test
npm run exampleContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Add tests for your changes
- Ensure all tests pass
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the Unlicense - see the LICENSE file for details.
- GitHub Repository
- Links Notation Specification
- PyPI Package (Python)
- npm Package (JavaScript)
This project is built on top of the links-notation library.