Skip to main content

Crate oxml_json

Crate oxml_json 

Source
Expand description

A small JSON value, parser and serialiser.

This exists because two crates in the oxml suite speak JSON-RPC — oxml-mcp over the Model Context Protocol and oxml-lsp over the Language Server Protocol — and for a while each carried its own copy of this file. A defect fixed in one would not have reached the other, and nothing would have noticed.

§Scope

JSON-RPC messages are small and their shapes are fixed, so this implements what those protocols need rather than everything the grammar allows. It is not a general-purpose JSON library and does not try to be: if you want serde, use serde.

What it does do is refuse malformed input rather than guess at it, and it is fuzzed on every pull request.

§Numbers

This implementation stores numbers as f64; JSON itself does not require that representation. An integer beyond 2^53 does may lose precision. Callers requiring larger exact integers must use a different representation. The LSP transport uses this crate; MCP uses its SDK’s JSON implementation.

use oxml_json::{parse, Json};

let value = parse(r#"{"jsonrpc":"2.0","id":1}"#).expect("valid JSON");
assert_eq!(value.get("jsonrpc").and_then(Json::as_str), Some("2.0"));

Enums§

Json
A JSON value.

Functions§

parse
Parse JSON text.