Skip to content

About

Zero-dependency JSON library with full RFC 8259 parsing, serialization, SAX-style streaming, NDJSON, JSON Pointer (RFC 6901), JSON Patch (RFC 6902), and schema validation (Rust/TS/Python/Go/PHP).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LombokJSON

Zero-dependency JSON library with full RFC 8259 parsing, serialization, SAX-style streaming, NDJSON, JSON Pointer (RFC 6901), JSON Patch (RFC 6902), and schema validation (Rust/TS/Python/Go/PHP).

Part of LombokRAGFrameworks — Library #07.

Features

  • Full JSON Parser — RFC 8259 compliant with proper Unicode/surrogate pair handling
  • Serializer — Compact and pretty-printed output with sorted keys
  • Streaming — SAX-style event-based parsing for large documents
  • NDJSON — Parse and serialize newline-delimited JSON
  • JSON Pointer — RFC 6901 path resolution with ~0/~1 escaping
  • JSON Patch — RFC 6902 operations (add, remove, replace, move, copy, test)
  • Schema Validation — Type, required, enum, min/max, minLength/maxLength, nested properties/items
  • Zero Dependencies — Every language uses only its standard library

Quick Start

Rust

[dependencies]
lombokjson = { path = "rust" }
use lombokjson::{parse, to_string, to_string_pretty, pointer, patch, validate};

// Parse
let val = parse(r#"{"name":"Lombok","version":7}"#).unwrap();

// Access
let name = &val["name"];  // Index trait

// Serialize
let compact = to_string(&val);
let pretty = to_string_pretty(&val, 2);

// JSON Pointer
let v = pointer(&val, "/name").unwrap();

// JSON Patch
let patched = patch(val, &[PatchOp { op: "add", path: "/new", value: Some(JsonValue::Str("hi".into())), from: None }]).unwrap();

TypeScript

import { parse, toString, toStringPretty, StreamParser, parseNdjson, pointer, applyPatch, validate } from 'lombokjson';

// Parse & serialize
const obj = parse('{"a":1,"b":[true,null]}');
const json = toString(obj);
const pretty = toStringPretty(obj, 2);

// Streaming
const sp = new StreamParser('{"key":"value"}');
let event;
while ((event = sp.next()) !== null) {
  console.log(event.type, event.value);
}

// JSON Pointer
const val = pointer(obj, '/b/0'); // true

// JSON Patch
const patched = applyPatch(obj, [{ op: 'add', path: '/c', value: 3 }]);

// Schema validation
const errors = validate(obj, { type: 'object', required: ['a'] });

Python

from lombokjson import parse, to_string, to_string_pretty, StreamParser, parse_ndjson, json_pointer, apply_patch, validate

# Parse & serialize
obj = parse('{"a": 1, "b": [true, null]}')
json_str = to_string(obj)
pretty = to_string_pretty(obj)

# Streaming
sp = StreamParser('{"key": "value"}')
while (event := sp.next_event()) is not None:
    print(event)

# JSON Pointer
val = json_pointer(obj, '/b/0')  # True

# JSON Patch
patched = apply_patch(obj, [{'op': 'add', 'path': '/c', 'value': 3}])

# Schema validation
errors = validate(obj, {'type': 'object', 'required': ['a']})

Go

import lj "github.com/codinglombok/LombokJSON/go"

// Parse & serialize
val, err := lj.Parse(`{"a":1,"b":[true,null]}`)
compact := lj.ToString(val)
pretty := lj.ToStringPretty(val, 2)

// Access
a, ok := val.Get("a").AsI64() // 1, true
item := val.Get("b").Index(0) // Bool true

// JSON Pointer
result := lj.Pointer(val, "/b/0")

// JSON Patch
patched, err := lj.ApplyPatch(val, []lj.PatchOp{
    {Op: "add", Path: "/c", Value: lj.Number(3)},
})

// Schema validation
schema, _ := lj.Parse(`{"type":"object","required":["a"]}`)
errors := lj.Validate(val, schema)

PHP

use LombokJSON\LombokJson;
use LombokJSON\StreamParser;

// Parse & serialize
$obj = LombokJson::parse('{"a":1,"b":[true,null]}');
$json = LombokJson::toString($obj);
$pretty = LombokJson::toStringPretty($obj);

// Streaming
$sp = new StreamParser('{"key":"value"}');
while (($event = $sp->nextEvent()) !== null) {
    echo $event[0] . ': ' . var_export($event[1], true) . "\n";
}

// JSON Pointer
$val = LombokJson::pointer($obj, '/b/0'); // true

// JSON Patch
$patched = LombokJson::applyPatch($obj, [
    ['op' => 'add', 'path' => '/c', 'value' => 3],
]);

// Schema validation
$errors = LombokJson::validate($obj, ['type' => 'object', 'required' => ['a']]);

Testing

# Rust
cd rust && cargo test

# TypeScript
cd typescript && npx tsx src/test.ts

# Python
cd python && python tests/test_smoke.py

# Go
cd go && go test -v ./...

# PHP
cd php && php tests/smoke.php

Architecture

LombokJSON/
  rust/          — Core Rust implementation (no_std compatible)
  typescript/    — TypeScript/ESM port
  python/        — Python port (stdlib only)
  go/            — Go port (idiomatic)
  php/           — PHP 8.1+ port

License

Apache 2.0 — see LICENSE.

About

Zero-dependency JSON library with full RFC 8259 parsing, serialization, SAX-style streaming, NDJSON, JSON Pointer (RFC 6901), JSON Patch (RFC 6902), and schema validation (Rust/TS/Python/Go/PHP).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages