Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# .gitkeep file auto-generated at 2026-05-10T19:22:27.543Z for PR creation at branch issue-35-03946ff48852 for issue https://github.com/link-foundation/lino-objects-codec/issues/35
54 changes: 36 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ npm install lino-objects-codec
```

```javascript
import { encode, decode } from 'lino-objects-codec';
import { formatIndented, parseIndented } from "lino-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
// Readable indented Links Notation for repository data
const data = { name: "Alice", age: 30, active: true };
const text = formatIndented({ id: "obj_root", obj: data });
const { obj } = parseIndented({ text });
console.log(JSON.stringify(obj) === JSON.stringify(data)); // true
```

### Rust
Expand Down Expand Up @@ -166,6 +166,7 @@ All implementations support the same features with language-appropriate syntax:
### Circular References

**Python:**

```python
from link_notation_objects_codec import encode, decode

Expand All @@ -177,8 +178,9 @@ assert decoded[3] is decoded # Reference preserved
```

**JavaScript:**

```javascript
import { encode, decode } from 'lino-objects-codec';
import { encode, decode } from "lino-objects-codec";

// Self-referencing array
const arr = [1, 2, 3];
Expand All @@ -188,6 +190,7 @@ console.log(decoded[3] === decoded); // true - Reference preserved
```

**Rust:**

```rust
use lino_objects_codec::{encode, decode, LinoValue};

Expand All @@ -199,6 +202,7 @@ let decoded = decode(&encoded).unwrap();
```

**C#:**

```csharp
using Lino.Objects.Codec;

Expand All @@ -212,6 +216,7 @@ Console.WriteLine(ReferenceEquals(decoded, decoded?[0])); // True - Reference pr
### Complex Nested Structures

**Python:**

```python
data = {
"users": [
Expand All @@ -224,18 +229,20 @@ assert decode(encode(data)) == data
```

**JavaScript:**

```javascript
const data = {
users: [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' }
{ id: 1, name: "Alice" },
{ id: 2, name: "Bob" },
],
metadata: { version: 1, count: 2 }
metadata: { version: 1, count: 2 },
};
console.log(JSON.stringify(decode(encode(data))) === JSON.stringify(data));
```

**Rust:**

```rust
use lino_objects_codec::{encode, decode, LinoValue};

Expand All @@ -253,6 +260,7 @@ assert_eq!(decode(&encode(&data)).unwrap(), data);
```

**C#:**

```csharp
var data = new Dictionary<string, object?>
{
Expand All @@ -273,27 +281,34 @@ var decoded = Codec.Decode(Codec.Encode(data));
The indented format provides a human-readable representation for displaying objects:

**JavaScript:**

```javascript
import { formatIndented, parseIndented } from 'lino-objects-codec';
import { formatIndented, parseIndented } from "lino-objects-codec";

// Format an object with an identifier
const formatted = formatIndented({
id: '6dcf4c1b-ff3f-482c-95ab-711ea7d1b019',
obj: { uuid: '6dcf4c1b-ff3f-482c-95ab-711ea7d1b019', status: 'executed', command: 'echo test', exitCode: '0' }
id: "6dcf4c1b-ff3f-482c-95ab-711ea7d1b019",
obj: {
uuid: "6dcf4c1b-ff3f-482c-95ab-711ea7d1b019",
status: "executed",
command: "echo test",
exitCode: "0",
},
});
console.log(formatted);
// Output:
// 6dcf4c1b-ff3f-482c-95ab-711ea7d1b019
// uuid "6dcf4c1b-ff3f-482c-95ab-711ea7d1b019"
// status "executed"
// command "echo test"
// exitCode "0"
// 6dcf4c1b-ff3f-482c-95ab-711ea7d1b019:
// uuid '6dcf4c1b-ff3f-482c-95ab-711ea7d1b019'
// status executed
// command 'echo test'
// exitCode '0'

// Parse it back
const { id, obj } = parseIndented({ text: formatted });
```

**Python:**

```python
from link_notation_objects_codec import format_indented, parse_indented

Expand All @@ -308,6 +323,7 @@ id, obj = parse_indented(formatted)
```

**Rust:**

```rust
use lino_objects_codec::format::{format_indented_ordered, parse_indented};

Expand All @@ -320,6 +336,7 @@ let (id, obj) = parse_indented(&formatted).unwrap();
```

**C#:**

```csharp
using Lino.Objects.Codec;

Expand All @@ -345,6 +362,7 @@ The library uses the [links-notation](https://github.com/link-foundation/links-n
- Circular references use direct object ID references: `obj_0` (without the `ref` keyword)

This approach allows for:

- Universal representation of object graphs
- Preservation of object identity
- Natural handling of circular references using built-in links notation syntax
Expand Down
5 changes: 5 additions & 0 deletions js/.changeset/readable-indented-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'lino-objects-codec': minor
---

Add recursive readable indented object formatting and parsing for untyped repository data.
Loading
Loading