Expand description
Lossless TOML ↔ JSON translation.
tomljson translates serde_json::Value to TOML and back, handling the
representational gaps where TOML can’t express something JSON can:
- Null: TOML has no null type. JSON
nullis encoded as a string placeholder (default"__null__", configurable viaTomlJsonOptions). Decoding substitutes the placeholder back to JSONnull. - Top-level non-table values: TOML documents must be a table at the
root. Non-table JSON values (booleans, scalars, arrays) are wrapped under
a reserved
__root__key on encode and unwrapped on decode. - Integer range: TOML integers are signed 64-bit. Encoding refuses
values larger than
i64::MAX(per TOML’s spec, not a tomljson limitation).
The motivating use case is JSON Schema 2020-12 documents authored as TOML.
tomljson is mdvs-agnostic — anyone moving JSON-shaped data through TOML
can use it.
§Quick start
use serde_json::json;
let value = json!({
"type": "object",
"properties": {
"name": { "type": "string" }
}
});
let toml_str = tomljson::to_string(&value).unwrap();
let back = tomljson::from_str(&toml_str).unwrap();
assert_eq!(back, value);Structs§
- Toml
Json Options - Options for encode and decode operations.
Enums§
- Error
- Errors produced by
tomljson’s encode and decode paths.
Constants§
- DEFAULT_
NULL_ PLACEHOLDER - Default placeholder string for JSON
nullvalues. - DEFAULT_
ROOT_ PLACEHOLDER - Default key used to wrap top-level non-table JSON values (booleans, scalars, arrays) in TOML output, since TOML documents must have a table at the root.
Functions§
- from_
str - Decode a TOML string to a JSON value using default options.
- from_
str_ with_ options - Decode a TOML string to a JSON value.
- to_
string - Encode a JSON value to TOML using default options.
- to_
string_ with_ options - Encode a JSON value to a TOML string.
Type Aliases§
- Result
- Convenience alias for
Result<T, tomljson::Error>.