Skip to main content

Crate tilewright_jsonc

Crate tilewright_jsonc 

Source
Expand description

Strict, lossless, bounded JSONC for Tilewright world sources.

The dialect is UTF-8 JSON (RFC 8259) plus // and /* */ comments, as specified in docs/spec/FORMAT.md section 3. Trailing commas, duplicate keys, byte-order marks, non-finite numbers and out-of-range integers are errors. Every limit is enforced while reading.

A Document keeps its source text unchanged. Every Value records the byte Span it occupies, so tools can replace exactly one value and keep comments, ordering and whitespace byte for byte.

use tilewright_jsonc::{Document, Limits};

let source = "{\n  // terrain\n  \"fill\": 0\n}\n";
let document = Document::parse(source, &Limits::default()).unwrap();
let fill = document.root().get("fill").unwrap();
assert_eq!(fill.as_i64(), Some(0));
let edited = document.replace(fill.span(), "4", &Limits::default()).unwrap();
assert_eq!(edited.source(), "{\n  // terrain\n  \"fill\": 4\n}\n");

Structs§

Document
A parsed document that owns its unchanged source text.
Error
A parse error. line and column are 1-based (column counts characters); both are 0 when no position applies.
Limits
Parser limits. Limits::default is the format’s fixed contract.
Member
One object member. Members keep their source order.
Span
A half-open byte range [start, end) in the document source.

Enums§

ErrorCode
Stable error codes.
Segment
A step in a Value::pointer path.
Value
A parsed value with its exact source span.

Constants§

MAX_SAFE_INTEGER
Largest integer magnitude accepted, 2^53 - 1.

Functions§

write_json_string
Appends value as a JSON string with minimal escaping.