to_json_compact
Stable function · Document I/O
Tier: stable · Kind: function · Topic: Document I/O
| Julia | TypeScript | Python | Rust | Go |
|---|---|---|---|---|
to_json_compact | toJsonCompact | to_json_compact | to_json_compact | ToJSONCompact |
Julia
to_json_compact(file::EsmFile)
to_json_compact(file::EsmFile) -> String
The single-line wire form. Exists in every binding for call-site parity —
Rust and Go have no default arguments and so cannot express
to_json(file, indent=0).
In THIS binding it returns exactly what to_json
returns, because
JSON3 already emits the compact form (see to_json).
TypeScript
function toJsonCompact(file: EsmFile, options?: ToJsonOptions): string
toJson
with no indentation — the single-line wire form. Present in
every binding, because Rust and Go have no default arguments and so cannot
express toJson(file, { indent: 0 }).
Python
to_json_compact(esm_file: EsmFile) -> str
to_json
with no indentation — the single-line wire form.
Present in every binding, because Rust and Go have no default arguments
and so cannot express to_json(file, indent=0).
Example (to_json_compact)
compact = earthsci_ast.to_json_compact(doc)
assert "\n" not in compact and compact.startswith('{"esm":')
assert json.loads(compact) == json.loads(earthsci_ast.to_json(doc))
Rust
pub fn to_json_compact(esm_file: &EsmFile) -> Result<String, EsmError>
Serialize an ESM file to compact JSON string (no pretty printing)
This function is similar to to_json
but produces compact JSON without
extra whitespace, suitable for storage or transmission. It is a separate
function rather than a to_json(file, opts) flag because Rust has no
default arguments and a one-field options struct plus a
to_json_with_options twin is heavier than the pair.
Arguments
esm_file- The ESM file to serialize
Returns
Ok(String)- Successfully serialized compact JSON stringErr(EsmError)- Serialization error