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
Numbers are f64, which is what JSON’s grammar describes and what
both protocols use for ids and codes. An integer beyond 2^53 does
not survive, which no request id in either protocol reaches.
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.